UIButton状态:
UIControlStateNormal // 正常状态
UIControlStateHighlighted // 高亮状态
UIControlStateDisabled // 禁用状态
UIControlStateSelected // 选中状态
UIControlStateApplication //
UIControlStateReserved // 保留状态
UIButton类型:
UIButtonTypeCustom //自定义类型
[pre]添加图片: [/pre][pre]
[pre]灰色背景颜色:[/pre]
[pre]UIButtonTypeRoundedRect //圆角类型[/pre]
UIButtonTypeDetailDisclosure //细节展示按钮
UIButtonTypeInfoLight //浅色背景的信息按钮
UIButtonTypeInfoDark //暗色背景的信息按钮
UIButtonTypeContactAdd // 添加按钮 www.2cto.com
UIButton *pushButton = [UIButton buttonWithType:UIButtonTypeCustom];//创建UIButton
[pushButton setTitle:@"push" forState:UIControlStateNormal];//设置UIButton标题
[pushButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];//设置标题颜色
[pushButton setBackgroundImage:sBlueImage forState:UIControlStateNormal];//设置背景图片
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 状态栏高 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);
设置视图背景图片
UIImageView *aView;
[aView setImage:[UIImage imageNamed:@”name.png”]];
view1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image1.png"]];
活动表单 <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];
}
}
initWithTitle:警告框标题
message:警告内容
delegate:接收对象
cancelButtonTitle:关闭按钮标题
otherButtonTitles:其他按钮
动画效果
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:0.8];
[UIViewsetAnimationRepeatAutoreverses:YES];
[UIViewsetAnimationRepeatCount:4];
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.viewcache:YES];
[self.viewaddSubview:imageView];
[UIViewcommitAnimations];
iOS 判断当前设备为iPhone还是iPad
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
}
else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
}