No.2 (code 2.0)UIButton
来源:互联网 发布:软件卸载大师 编辑:程序博客网 时间:2024/05/21 09:46
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];//去使被使用对象的主窗口显示到屏幕的最前端。你也可以使用hiddenUIView方法隐藏这个窗口
//以下是UILabel:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 100, 70)];//设置label位置和大小
label.backgroundColor = [UIColor yellowColor];//设置label的背景颜色
label.text = @"hello, world, hello, worldhello, worldhello, worldhello, world";//设置label里的文字信息
label.textColor = [UIColor redColor];//设置文字颜色
label.textAlignment = NSTextAlignmentCenter;//设置文本对齐方式
label.font = [UIFont systemFontOfSize:12.0];//设置字体大小
label.numberOfLines = 0;//行数没有限制,只要高度够,我就让你文本全部显示
label.lineBreakMode = NSLineBreakByWordWrapping;//和numberOfLines组合使用,以什么换行(这里选择的是word)如果后面剩下的宽度不能够容纳一个单词那么就换行。
[self.window addSubview:label];
[label release];
//以下是textField:
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 90, 200, 30)];
textField.borderStyle = UITextBorderStyleRoundedRect;
//UITextBorderStyleNone 没有边框
//UITextBorderStyleLine 边框是直线的
//UITextBorderStyleBezel 切斜面
//UITextBorderStyleRoundedRect 圆角
// textField.keyboardType = UIKeyboardTypeNamePhonePad;//设置默认弹出的键盘样式
textField.secureTextEntry = YES;//如果是yes就是暗文输入
textField.delegate = self;//设置代理对象为当前类(那么当前类就得实现协议的方法)(具体什么协议conmmand+delegate查看)
textField.placeholder = @"请输入用户名:";//当然也可以设置。text值,就是默认显示的文本信息,但是placeholder叫做提示文本信息(当textField文本框里面没有内容时候提示的内容)。
[self.window addSubview:textField];
[textField release];
//以下是UIButton:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//创建一个custom类型的按钮
//UIButtonTypeCustom = 0, 自定义,无风格
//UIButtonTypeRoundedRect, 白色圆角矩形,类似偏好设置表格单元或者地址簿卡片
//UIButtonTypeDetailDisclosure,//蓝色的披露按钮,可放在任何文字旁
//UIButtonTypeInfoLight,//微件(widget)使用的小圆圈信息按钮,可以放在任何文字旁
//UIButtonTypeInfoDark,//白色背景下使用的深色圆圈信息按钮
button.frame = CGRectMake(20, 500, 100, 30);
[button.layer setCornerRadius:8];//设置按钮圆角
[button setBackgroundColor:[UIColor grayColor]];
[button addTarget:self action:@selector(downClick:) forControlEvents:UIControlEventTouchDown];//当按下按钮时候触发upClick方法。
[button addTarget:self action:@selector(doClick:) forControlEvents:UIControlEventTouchUpInside];//当抬起的时候触发doClick方法。
[button setTitle:@"normal" forState:UIControlStateNormal];//默认情况下,按钮上的文字是normal
[button setTitle:@"hightLight" forState:UIControlStateHighlighted];//当按钮被按下时候,按钮上的文字显示的是hightLight
// [button setBackgroundImage:<#(UIImage *)#> forState:<#(UIControlState)#>];//在什么状态下让按钮显示什么图片,UIImage是图片的路径。
button.showsTouchWhenHighlighted = YES;//yes设置高亮状态,就是当按下按钮时候中间会很亮。
[self.window addSubview:button];
return YES;
}
- (void)downClick:(UIButton *)button
{
button.backgroundColor = [UIColor blueColor];
NSString *title = [button titleForState:UIControlStateNormal];//titleForState 方法是得到这个按钮在什么状态下的title的文字信息。
NSLog(@"%@", title);
}
- (void)doClick:(UIButton *)button
{
button.backgroundColor = [UIColor grayColor];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField//当点击键盘上的return键响应这个方法。
{
[textField resignFirstResponder];//textField失去第一响应者身份(因为软键盘是textField调用出来的,所以取消textField的第一响应者身份就取消了软键盘。)
return YES;
}
0 0
- No.2 (code 2.0)UIButton
- code kata NO.2 : Karate Chop
- no-generic code
- code Kata NO.1
- VAT code & VAT NO.
- No code signature found
- NO CODE SIGNING ENTITLEMENTS 解决办法
- LeeCode No.89 Gray Code
- Use code to add UILabel and UIButton----iphone
- UIButton
- UIButton
- UIButton
- uibutton
- UIButton
- UIButton
- UIButton
- UIButton
- UIButton
- Activity传递数据的几种方式及返回结果
- iOS中 UIButton和UIImageView
- 深入Mysql字符集设置 图文版
- Zookeeper伪分布安装
- qmake 命令行参数
- No.2 (code 2.0)UIButton
- linux程序设计第2章末程序1
- poj 3260 The Fewest Coins
- vi编辑只读文档无法保存的解决办法
- Practical C Programming - Chapter 5
- Special的——动态规划入门教程
- Android完全退出应用程序
- [总结]FFMPEG视音频编解码零基础学习方法
- Java中Object类的clone()(克隆)方法