#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;
}
UI笔记:UILabel、UIButton和UITextField
最新推荐文章于 2024-09-18 12:25:09 发布