UIButton, UILabel, UITextField
2016-01-02 18:00
387 查看
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor brownColor]; [self.window makeKeyAndVisible]; /* UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; view.backgroundColor = [UIColor whiteColor]; view.hidden = NO; view.alpha = 1; view.clipsToBounds = NO; // view.superview // view.subviews view.frame = CGRectMake(100, 200, 300, 400); view.center = CGPointMake(100, 100); view.bounds = CGRectMake(0, 0, 300, 400); view.layer.cornerRadius = 50; [self.window addSubview:view]; */ //UILabel, 标签视图, 用于显示文字, 继承于UIView label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 335, 40)];//对称 label.backgroundColor = [UIColor whiteColor]; //设置文本 label.text = @"joner , goog moring, you are good!"; //cmd + ctrl + 空格(添加表情) //设置对齐方式, 默认是左对齐 label.textAlignment = NSTextAlignmentCenter; //文本颜色, 默认为黑色 label.textColor = [UIColor redColor]; //行数,默认为1, 首先要改标签视图高度; 0,代表自动匹配 label.numberOfLines = 0; //字体(样式和大小), 默认为17 UIFont *font1 = [UIFont systemFontOfSize:20]; //加粗(注:后面的数值是字体大小) UIFont *font2 = [UIFont boldSystemFontOfSize:40]; //斜体 UIFont *font3 = [UIFont italicSystemFontOfSize:30]; UIFont *font4 = [UIFont fontWithName:@"Heiti SC" size:30]; NSLog(@"%@", [UIFont familyNames]); label.font = font3; //文字的阴影 label.shadowColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.2]; label.shadowColor = [UIColor blueColor]; //文字阴影偏移量, 默认(0, -1) label.shadowOffset = CGSizeMake(0, -5); //换行模式(英文用的居多) label.lineBreakMode = NSLineBreakByCharWrapping ; //直接点击cmd ,进入查看 //同理 label.tag = 102; [self.window addSubview:label]; [label release];//但在ARC, 编译器释放 //UITextField, 单行文本输入框, 继承于UIContrl textField1 = [[UITextField alloc] initWithFrame:CGRectMake(20, 160, 335, 40)]; // textField.backgroundColor = [UIColor whiteColor]; //文本 // textField.text = @"辉哥真帅"; //占位符(提示) textField1.placeholder = @"请输入口令";//不写内容就会出来 //文字颜色 textField1.textColor = [UIColor blueColor]; //字体 textField1.font = [UIFont systemFontOfSize:35]; //边框样式 textField1.borderStyle = UITextBorderStyleRoundedRect; //圆角样式: 默认为白色, 就算注释了文本框, 圆角样式: 他会自动生成 //对齐方式 textField1.textAlignment =NSTextAlignmentLeft; //是否可用(无法写入) textField1.enabled = YES; //是否安全输入(密码, 变星号) textField1.secureTextEntry = NO; //换行键样式 textField1.returnKeyType = UIReturnKeySearch; //代理 textField1.delegate = self;//确定关系 //弹出键盘的类型 textField1.keyboardType = UIKeyboardTypeNumberPad; //设置一个标签值 textField1.tag = 101; //(要写到100以上, 100以下, 系统可能在用) [self.window addSubview:textField1]; [textField1 release]; UIControl //UIButton, 按钮类, 继承于UIControl UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; //便利构造器(不需要释放); 渲染色系统自带为蓝色 button.frame = CGRectMake(20, 220, 335, 40); button.backgroundColor = [UIColor greenColor]; //1 设置对应状态下的标题 [button setTitle:@"按住说话" forState:UIControlStateNormal];// 正常情况, 就用normal [button setTitle:@"松开结束" forState:UIControlStateHighlighted];// 正常情况, 就用normal // [button setTitle:@"好幸运, 被翻到了" forState:UIControlStateSelected];// 配合 button.selected = YES; // [button setTitle:@"你是不是有别人了" forState:UIControlStateDisabled];// 配合 button.enabled = NO; //是否选中 // button.selected = YES; //是否可用 // button.enabled = NO; //渲染色 tintColor button.tintColor = [UIColor redColor]; //2 设置某个状态下的显示图片 //注意: 如果需要显示图片, 要去掉渲染色, 使用UIButtonTypeCustom UIImage *image = [UIImage imageNamed:@"abc.png"]; //图片如果是png, 可以省略后缀, 其他类型, 必须加上后缀 // [button setImage:image forState:UIControlStateNormal]; //注: title 和 image 是在同一层的, 如果图片过大, 就会把标题挤走.(setImage) //3 图片作为背景色 [ button setBackgroundImage:image forState:UIControlStateNormal]; //button是复合视图, button上有一个用于展示文字的titleLable, 可以修改相关属性 // button.titleLabel.textColor = [UIColor blueColor]; //4 设置执行状态下的标题颜色 [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; //注: 修改button的title, titleColor, image, backgroundImage //点击button, 触发某些方法 //1. 方法执行者 //2.方法名 //3.方法触发的时刻 [button addTarget:self action:@selector(pressButton) forControlEvents:UIControlEventTouchUpInside ]; //UIImageView, 用于显示图片, 继承于UIView UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]]; imageView.frame = CGRectMake(37.5, 280, 300, 300); NSMutableArray *images = [NSMutableArray arrayWithCapacity:4]; for (NSInteger i = 1; i <= 4; i++) { NSString *name = [NSString stringWithFormat:@"%ld", i]; UIImage *image = [UIImage imageNamed:name]; [images addObject:image]; } //设置动画数组 imageView.animationImages = images; //设置动画时间 imageView.animationDuration = 0.5; // imageView.animationRepeatCount = 3;//(3轮就停止) [self.window addSubview:imageView]; [imageView release]; //动起来 [imageView startAnimating]; //停止动画 // [imageView stopAnimating]; [self.window addSubview:button]; return YES; } - (void)pressButton { NSLog(@"点击了按钮"); //1.扩大作用域(写成实例变量) //注: NSLog(@"%@", textField1.text); //打印到后台; text 表示文本 label.text = textField1.text; //2. 通过tag值(多个相同视图) //做强制转换 UITextField *tf = (UITextField *)[self.window viewWithTag:101]; NSLog(@"%@", tf.text); UILabel *la = (UILabel *)[self.window viewWithTag:102]; NSLog(@"%@", la.text); la.text = tf.text; }
相关文章推荐
- UISwitch 开关控件
- UEFI不小心误删EPS分区里的grub引导恢复
- 加载EasyUi和使用Parser解析器
- UIView属性
- POJ-3061 Subsequence(尺取法)
- 二分+线段树 Codeforces609F Frogs and mosquitoes
- Java基础之break和continue
- UITableView 滚动流程性优化
- ArrayBlockingQueue 和LinkedBlockingQueue
- BlockingQueue
- LeetCode 95:Unique Binary Search Trees II
- Android UI标题栏模板设计
- sendAsynchronousRequest 过时
- incredibuild教程
- (java多线程与并发)java并发库中的阻塞队列--BlockingQueue
- Leetcode: Range Sum Query - Mutable && Summary: Segment Tree
- Deep learning From Image to Sequence
- query的参数解析
- codeforces 375D . Tree and Queries 启发式合并 || dfs序+莫队
- Linguistic Data Consortium (LDC)