UI笔记:UILabel、UIButton和UITextField
来源:互联网 发布:java的反射如何实现 编辑:程序博客网 时间:2024/06/06 15:02
#import "AppDelegate.h"@interface AppDelegate (){ UIImageView *flagImageView;}@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor colorWithRed:48/255.0 green:152/255.0 blue:244/255.0 alpha:1.0]; //按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake((375-120)/2, 40, 120, 40); [button setBackgroundImage:[UIImage imageNamed:@"smallHeader"] forState:0]; //圆角 button.layer.cornerRadius = 20/2; button.layer.masksToBounds = YES; //tittle [button setTitle:@"按钮" forState:0]; //tittle字体 button.titleLabel.font = [UIFont systemFontOfSize:20]; //设置自然状态下的颜色RGB [button setTitleColor:[UIColor colorWithRed:2/255.0 green:23/255.0 blue:52/255.0 alpha:1.0] forState:0]; //UIControlEventTouchDown按在按钮状态,此状态下执行方法buttonActionTouchDown: [button addTarget:self action:@selector(buttonActionTouchDown:) forControlEvents:UIControlEventTouchDown]; //不可编辑状态 [button setTitle:@"不可编辑状态" forState:UIControlStateDisabled];// button.enabled = NO; //UIControlEventTouchUpInside按下放开过程,此过程执行方法buttonActionTouchUpInside: [button addTarget:self action:@selector(buttonActionTouchUpInside:) forControlEvents:UIControlEventTouchUpInside]; //建立图片视图,初始化图片header(png格式) flagImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]]; //设置视图大小和位置 flagImageView.frame = CGRectMake((375-82)/2, 120, 82, 82); //视图圆角 flagImageView.layer.cornerRadius = 40/2; flagImageView.layer.masksToBounds = YES; //隐藏视图 flagImageView.hidden = YES; //设置视图动画时间 flagImageView.animationDuration = 0.8; //播放的内容是两张图片 flagImageView.animationImages = @[[UIImage imageNamed:@"header"],[UIImage imageNamed:@"kongjiantouxiang"]]; //播放重复次数为最大浮点数。 flagImageView.animationRepeatCount = FLT_MAX; UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectZero]; NSString *string = @"狂风呼啸、暴雨倾泻"; label2.text = string; label2.font = [UIFont systemFontOfSize:24];// label2.font = [UIFont fontWithName:<#(NSString *)#> size:<#(CGFloat)#>]; CGSize size = [string sizeWithAttributes:@{NSFontAttributeName:label2.font}]; label2.frame = CGRectMake(50, 220, size.width, size.height); UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; string = @"狂风呼啸、暴雨倾泻、惊涛骇浪,顷刻间,山洪暴发、山体滑坡、泥石流、房屋倒塌、江河满溢、道路中断、村庄被淹、农田被毁......这是台风“苏迪罗”肆虐温州南部县市的灾难景象。"; label.text = string; //不限制label的行数 label.numberOfLines = 0; //省略符合位置 label.lineBreakMode = NSLineBreakByTruncatingMiddle; //label.text的大小; CGRect rect = [label.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 300) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil]; //颜色 label.backgroundColor = [UIColor yellowColor]; //设置frame label.frame = CGRectMake(0, 260, rect.size.width, rect.size.height); //添加控件 [self.window addSubview:label2]; [self.window addSubview:label]; [self.window addSubview:flagImageView]; [self.window addSubview:button]; [self.window makeKeyAndVisible]; return YES;}-(void) buttonActionTouchDown:(UIButton *)sender { flagImageView.hidden = NO; [flagImageView startAnimating];}-(void) buttonActionTouchUpInside:(UIButton *) sender { flagImageView.hidden = YES; [flagImageView stopAnimating]; sender.enabled = NO;}
0 0
- UI笔记:UILabel、UIButton和UITextField
- 初始UI(UILabel、UIButton、UITextField)
- UI - UITextField和UIButton
- UI基本控件-UILabel-UITextField-UIButton-UIAlertView
- IOS UI 代码创建UIButton,UITextField,UILabel
- UI课程02 UILabel,UITextField,UIButton
- UI-基本控件( UILabel UITextField UIImageView UIButton)
- **原创**零基础学ios**UI课程01***课堂笔记整理*UIView UILabel UIButton UITextField**
- UI 03 UIButton 和 UITextField
- UILabel,UITextField和UIButton使用简示
- UIButton,UIImageView,UILabel,UITextField
- UITextField、UILabel、UIButton
- UILabel, UITextField, UIButton
- UILabel,UITextField,UIButton
- UIView UILabel UITextField UIButton
- UILabel、UITextField、UIButton
- UIButton, UILabel, UITextField
- UILabel,UITextField,UIButton,UIimageView
- 1001 - Say Cheese (Dijkstra算法)
- Oracle 中查看用户建立的所有触发器
- 基于java的挖地雷游戏
- Activity 生命周期
- thinking in java 学习笔记(一)
- UI笔记:UILabel、UIButton和UITextField
- iOS 8 毛玻璃效果(模糊)
- 泛型(java基础)
- 经典排序算法1--冒泡排序
- Spring Security搭配hibernate,Mysql
- codeforces - 3C - Tic-tac-toe(模拟)
- Flickr Architecture
- 矩阵相乘这个代码也应该是需要掌握的内容,今天一大早就写了一下
- Java技术1-线程池