374016526 发表于 2013-1-14 21:20:58

ios开发小知识

<div style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff; margin: 8px;"> 
ios开发小知识2(转自cc)

<div class="postText" style="font-size: 10pt; padding-left: 5px; line-height: 1.5;"><div style="line-height: 1.8;">退回输入键盘
  - (BOOL)textFieldShouldReturn:(id)textField{
    ;
}
 
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);
 
设置透明度
; (0.0 < value < 1.0)

设置背景色
]; 
(blackColor;darkGrayColor;lightGrayColor;
whiteColor;grayColor;redColor; greenColor; 
blueColor;cyanColor;yellowColor;
magentaColor;orangeColor;purpleColor;
brownColor; clearColor;)

自定义颜色
UIColor *newColor = [
 initWithRed:(float) green:(float) blue:(float)alpha:(float)]; 
0.0~1.0

竖屏
320X480

横屏
480X320    

状态栏高(显示时间和网络状态)
20 像素   

导航栏、工具栏高(返回)
44像素

隐藏状态栏
[setStatusBarHidden: YES animated:NO]
 
横屏

setStatusBarOrientation:UIInterfaceOrientationLandscapeRight].

屏幕变动检测
orientation ==UIInterfaceOrientationLandscapeLeft

全屏
window=[ initWithFrame: bounds]; 
 
自动适应父视图大小:
aView.autoresizingSubviews = YES;
aView.autoresizingMask =(UIViewAutoresizingFlexibleWidth | 
                                      UIViewAutoresizingFlexibleHeight);

定义按钮
UIButton *scaleUpButton = ;
;
scaleUpButton.frame = CGRectMake(40, 420,100, 40);
[scaleUpButton addTarget:self
 action:@selector(scaleUp) 
forControlEvents:UIControlEventTouchUpInside];
 
设置视图背景图片
UIImageView *aView;
];
view1.backgroundColor = [UIColorcolorWithPatternImage:
];
 
自定义UISlider的样式和滑块

我们使用的是UISlider的setMinimumTrackImage,和setMaximumTrackImage方法来定义图片的,这两个方法可以设置滑块左边和右边的图片的,不过如果用的是同一张图片且宽度和控件宽度基本一致,就不会有变形拉伸的后果,先看代码,写在 viewDidLoad中:
   //左右轨的图片
页: [1]
查看完整版本: ios开发小知识