没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
更多苹果移动应用开发入门精选文档教程荟萃:http://down.51cto.com/zt/2401
苹果 ios 开发一年的工作笔记
退回输入键盘
- (BOOL) textFieldShouldReturn:(id)textField{
[textField resignFirstResponder];
}
CGRect
CGRect frame = CGRectMake (origin.x, origin.y, size.width, size.height);矩形
NSStringFromCGRect(someCG) 把 CGRect 结构转变为格式化字符串;
CGRectFromString(aString) 由字符串恢复出矩形;
CGRectInset(aRect) 创建较小或较大的矩形(中心点相同),+较小 -较大
CGRectIntersectsRect(rect1, rect2) 判断两矩形是否交叉,是否重叠
CGRectZero 高度和宽度为零的/位于(0,0)的矩形常量
CGPoint & CGSize
CGPoint aPoint = CGPointMake(x, y);
CGSize aSize = CGSizeMake(width, height);
设置透明度
[myView setAlpha:value]; (0.0 < value < 1.0)
设置背景色
[myView setBackgroundColor:[UIColor redColor]];
(blackColor;darkGrayColor;lightGrayColor;
whiteColor;grayColor; redColor; greenColor;
blueColor; cyanColor;yellowColor;
magentaColor;orangeColor;purpleColor;
brownColor; clearColor; )
自定义颜色
UIColor *newColor = [[UIColor alloc]
initWithRed:(float) green:(float) blue:(float) alpha:(float)];
0.0~1.0
竖屏
320X480
横屏
480X320
更多苹果移动应用开发入门精选文档教程荟萃:http://down.51cto.com/zt/2401
状态栏高 (显示时间和网络状态)
20 像素
导航栏、工具栏高(返回)
44 像素
隐藏状态栏
[[UIApplication shareApplication] setStatusBarHidden: YES animated:NO]
横屏
[[UIApplication shareApplication]
setStatusBarOrientation:UIInterfaceOrientationLandscapeRight].
屏幕变动检测
orientation == UIInterfaceOrientationLandscapeLeft
全屏
window=[[UIWindow alloc] initWithFrame:[UIScreen mainScreen] bounds];
自动适应父视图大小:
aView.autoresizingSubviews = YES;
aView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
定义按钮
UIButton *scaleUpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[scaleUpButton setTitle:@"放 大" forState:UIControlStateNormal];
scaleUpButton.frame = CGRectMake(40, 420, 100, 40);
[scaleUpButton addTarget:self
action:@selector(scaleUp)
forControlEvents:UIControlEventTouchUpInside];
设置视图背景图片
UIImageView *aView;
[aView setImage:[UIImage imageNamed:@”name.png”]];
view1.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:@"image1.png"]];
自定义 UISlider 的样式和滑块
更多苹果移动应用开发入门精选文档教程荟萃:http://down.51cto.com/zt/2401
我们使用的是 UISlider 的 setMinimumTrackImage,和 setMaximumTrackImage 方法来定义图
片的,这两个方法可以设置滑块左边和右边的图片的,不过如果用的是同一张图片且宽度和
控件宽度基本一致,就不会有变形拉伸的后果,先看代码,写在 viewDidLoad 中:
//左右轨的图片
UIImage *stetchLeftTrack= [UIImage imageNamed:@"brightness_bar.png"];
UIImage *stetchRightTrack = [UIImage imageNamed:@"brightness_bar.png"];
//滑块图片
UIImage *thumbImage = [UIImage imageNamed:@"mark.png"];
UISlider *sliderA=[[UISlider alloc]initWithFrame:CGRectMake(30, 320, 257, 7)];
sliderA.backgroundColor = [UIColor clearColor];
sliderA.value=1.0;
sliderA.minimumValue=0.7;
sliderA.maximumValue=1.0;
[sliderA setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[sliderA setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
//注意这里要加UIControlStateHightlighted的状态,否则当拖动滑块时滑块将变成原生的
控件
[sliderA setThumbImage:thumbImage forState:UIControlStateHighlighted];
[sliderA setThumbImage:thumbImage forState:UIControlStateNormal];
//滑块拖动时的事件
[sliderA addTarget:self action:@selector(sliderValueChanged:)
forControlEvents:UIControlEventValueChanged];
//滑动拖动后的事件
[sliderA addTarget:self action:@selector(sliderDragUp:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:sliderA];
为了大家实验方便,我附上背景图brightness_bar.png和滑块图mark.png
http://pic002.cnblogs.com/images/2011/162291/2011121611431816.png
http://pic002.cnblogs.com/images/2011/162291/2011121611432897.png
-(IBAction)sliderValueChanged:(id)sender{
UISlider *slider = (UISlider *) sender;
NSString *newText = [[NSString alloc] initWithFormat:@”%d”, (int)(slider.value + 0.5f)];
label.text = newText;
}
活动表单
更多苹果移动应用开发入门精选文档教程荟萃:http://down.51cto.com/zt/2401
<UIActionSheetDelegate>
- (IBActive) someButtonPressed:(id) sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@”Are you sure?”
delegate:self
cancelButtonTitle:@”No way!”
destructiveButtonTitle:@”Yes, I’m Sure!”
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
}
警告视图
<UIAlertViewDelegate>
- (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)
buttonIndex
{
if(buttonIndex != [actionSheet cancelButtonIndex])
{
NSString *message = [[NSString alloc] initWithFormat:@”You can
breathe easy, everything went OK.”];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@”Something was done”
message:message
delegate:self
cancelButtonTitle:@”OK”
otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
}
}
动画效果
-(void)doChange:(id)sender
{
if(view2 == nil)
{
[self loadSec];
更多苹果移动应用开发入门精选文档教程荟萃:http://down.51cto.com/zt/2401
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([view1
superview]?UIViewAnimationTransitionFlipFromLeft:UIViewAnimationTransitionFlipFromRigh
t)forView:self.view cache:YES];
if([view1 superview]!= nil)
{
[view1 removeFromSuperview];
[self.view addSubview:view2];
}else {
[view2 removeFromSuperview];
[self.view addSubview:view1];
}
[UIView commitAnimations];
}
Table View <UITableViewDateSource>
#pragma mark -
#pragma mark Table View Data Source Methods
//指定分区中的行数,默认为 1
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.listData count];
}
//设置每一行 cell 显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIndentifier = @"SimpleTableIndentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIndentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:SimpleTableIndentifier]
autorelease];
}
剩余55页未读,继续阅读
kaifaren2
- 粉丝: 17
- 资源: 40
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页