码迷,mamicode.com
首页 > 其他好文 > 详细

基础知识

时间:2015-03-01 13:03:52      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

退回输入键盘:

1
2
3
- (BOOL) textFieldShouldReturn:(id)textField{
    [textField  resignFirstResponder];
}

CGRect

1
2
3
4
5
6
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

1
CGPoint aPoint = CGPointMake(x, y);    CGSize aSize = CGSizeMake(width, height);

设置透明度

1
[myView setAlpha:value];   (0.0 < value < 1.0)

设置背景色

1
2
3
[myView setBackgroundColor:[UIColor redColor]];
   (blackColor;darkGrayColor;lightGrayColor;whiteColor;grayColor; redColor; greenColor; blueColor; cyanColor;yellowColor;magentaColor;
orangeColor;purpleColor;brownColor; clearColor; )

自定义颜色:

1
UIColor *newColor = [[UIColor alloc] initWithRed:(float) green:(float) blue:(float) alpha:(float)];      0.0~1.0

宽度和高度

1
768X1024     1024X768    状态栏高 20 像素高   导航栏 工具栏 44像素高

隐藏状态栏:

1
[[UIApplication shareApplication] setStatusBarHidden: YES animated:NO]

横屏:

1
2
3
[[UIApplication shareApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight].
orientation == UIInterfaceOrientationLandscapeLeft
window=[[UIWindow alloc] initWithFrame:[UIScreen mainScreen] bounds];全屏

自动适应父视图大小:

1
2
aView.autoresizingSubviews = YES;
aView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

定义按钮

1
2
3
4
UIButton *scaleUpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[scaleUpButton setTitle:@"放 大" forState:UIControlStateNormal];
scaleUpButton.frame = CGRectMake(40, 420, 100, 40);
[scaleUpButton addTarget:self action:@selector(scaleUp) forControlEvents:UIControlEventTouchUpInside];

设置视图背景图片

1
2
3
4
5
6
7
UIImageView *aView;
[aView setImage:[UIImage imageNamed:@”name.png”]];
view1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image1.png"]];
  
UISlider *slider = (UISlider *) sender;
NSString *newText = [[NSString alloc] initWithFormat:@”%d”, (int)(slider.value + 0.5f)];
label.text = newText;

活动表单 <UIActionSheetDelegate>

1
2
3
4
5
6
7
8
9
10
11
- (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>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- (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];
     }
}

基础知识

标签:

原文地址:http://www.cnblogs.com/haolianxue/p/4306837.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!