UI笔记:UILabel、UIButton和UITextField

#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值