UI 基本控件的常用方法


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    

    

    self.window = [[UIWindowalloc] initWithFrame:[UIScreenmainScreen].bounds];

    

    self.window.backgroundColor = [UIColorwhiteColor];

    

    [self.windowmakeKeyAndVisible];

    

    UIViewController *vc = [[UIViewControlleralloc] init];

    

    self.window.rootViewController = vc;

    

    [vc release];

    [self.windowrelease];

    

//    标签

    UILabel *lable = [[UILabelalloc] initWithFrame:CGRectMake(0,20, 300, 40)];

    

    lable.backgroundColor = [UIColorblackColor];

//    设置文本

    lable.text =@"男神最帅pppppppppppppppppppppppppppppppppppppppppppppppqweeeeeeeeeeeeeepppppppqqqqqqqqqqqqqqqqqqqqqqqqqq";

//    设置字体颜色

    lable.textColor = [UIColoryellowColor];

//    设置字体大小

    lable.font = [UIFontsystemFontOfSize:20];

//    文本的对其方式

    lable.textAlignment =NSTextAlignmentCenter;

//    行数

    lable.numberOfLines = 2;

//    断行方式

    lable.lineBreakMode =NSLineBreakByTruncatingMiddle;

//    阴影颜色

    lable.shadowColor = [UIColorredColor];

//    阴影大小

    lable.shadowOffset = CGSizeMake(5, 5);

//    设置标记

    lable.tag = 1001;

    

    [self.windowaddSubview:lable];

    

    [lable release];

    

//    文本输入框

    UITextField *textField = [[UITextFieldalloc] initWithFrame:CGRectMake(0,70, self.window.frame.size.width,20)];

    

    textField.backgroundColor = [UIColorredColor];

    

    [self.windowaddSubview:textField];

//    边框风格

    textField.borderStyle =UITextBorderStyleBezel;

    

//    设置占位符

    textField.placeholder = @"haha";

//    设置标记

    textField.tag = 1002;

    

//    获取文本输入框输入内容

//    textField.text;

//    设置输入文字的颜色

    textField.textColor = [UIColorwhiteColor];

//    文本对其方式 文本大小与UILable设置的方法相同

//    是否允许输入

//    NO - 不允许输入

    textField.enabled = YES;

//    是否开始输入的时候清空输入框内容

    textField.clearsOnBeginEditing =YES;

    

    

    UITextField *textField1 = [[UITextFieldalloc] initWithFrame:CGRectMake(0,100, self.window.frame.size.width,20)];

    

    textField1.backgroundColor = [UIColorredColor];

    

    textField1.textColor = [UIColorgreenColor];

    

    [self.windowaddSubview:textField1];

//    是否以圆点格式输入(密码)

    textField.secureTextEntry = YES;

//    设置键盘风格

    textField.keyboardType =UIKeyboardTypeNumberPad;

//    键盘右下角按钮类型

    textField.returnKeyType = UIReturnKeyGoogle;

    UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(0,0, 300, 200)];

    

    view.backgroundColor = [UIColorblueColor];

    

//    自定义输入试图(默认是键盘

//    多数使用自定义键盘

    textField1.inputView = view;

    

//    borderStyle - 边框样式(枚举值)

    textField1.borderStyle =UITextBorderStyleLine;

    

//    clearButtonMode - 清除按钮模式(枚举值)

//    leftView - 输入框左视图

//    leftViewMode - 左视图的显示模式

//    rightView - 输入框右视图

//    rightViewMode - 右视图的显示模式

    

    

//    图片显示

    UIImageView *imageView = [[UIImageViewalloc] initWithFrame:CGRectMake(0,130, self.window.frame.size.width,self.window.frame.size.width -100)];

    

    [self.windowaddSubview:imageView];

//    设置图片

    imageView.image = [UIImageimageNamed:@"2.jpg"];

    

    imageView.contentMode =UIViewContentModeScaleAspectFill;

    

//    控件

    UIButton *butten = [UIButtonbuttonWithType:UIButtonTypeCustom];

    

    butten.frame = CGRectMake(0, 400, self.window.frame.size.width,30);

    

    butten.backgroundColor = [UIColorpurpleColor];

    

//    按钮设置标题

//    参数1:按钮标题

//    参数2:显示这个标题的状态

    [butten setTitle:@"点我"forState:UIControlStateNormal];

    [butten setTitle:@"asdas"forState:UIControlStateSelected];

    

//    添加点击事件

    [butten addTarget:selfaction:@selector(buttonDidPress:)forControlEvents:UIControlEventTouchUpInside];

    

    [self.windowaddSubview:butten];

    

    

    [imageView release];

    [view release];

    [textField release];

    [textField1 release];

    return YES;

}


- (void)buttonDidPress:(UIButton *)sender {

    

    UILabel *label = [self.windowviewWithTag:1001];

    

    UITextField *textField = [self.windowviewWithTag:1002];

    

    label.text = textField.text;

    

//    取消键盘的方式

//    取消第一响应

    [textField resignFirstResponder];

    

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值