UI之button基础

来源:互联网 发布:辐射4导入捏脸数据 编辑:程序博客网 时间:2024/05/21 06:41

UIButton->UIControl->UIView->UIResponder->NSObject//继承关系

系统样式:

    UIButton * btn=[UIButtonbuttonWithType:UIButtonTypeCustom];

    btn.frame=CGRectMake(100, 100, 100, 100);

    [btn setTitle:@"文字"forState:UIControlStateNormal];

    [btn setTitleColor:[UIColor blueColor]forState:UIControlStateHighlighted];

    btn.titleLabel.font=[UIFontsystemFontOfSize:22];//字体

    [btn setTitleShadowColor:[UIColor redColor]forState:UIControlStateHighlighted];//阴影高亮

    btn.currentTitle;//拿到当前标题

    btn.currentTitleColor;//拿到标题颜色

    btn.currentTitleShadowColor;//阴影颜色

自定义样式:

UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];

    button.frame=CGRectMake(100, 220, 100,100);

    UIImage * image=[UIImageimageNamed:@"xx.jpg"];//用这种方式创建图片,图片会在内存中缓存一次,消耗内存比较大,而且释放是比较困难的事情,同一个图片只会缓存一次,这种方式适合拿比较小的图片或则可能频繁使用的图片

    [button setBackgroundImage:imageforState:UIControlStateNormal];//设置button背景图片,图片会铺满整个button,图片不够大会变形

    [button setImage:[UIImageimageNamed:@"xxx.jpg"] forState:UIControlStateNormal];//设置前景图片;如果足够大,会显示图片原本的尺寸,而且会现在button的正中间

    button.selected=YES;//设置button已经被点击,默认是no

    button.enabled=NO;//设置button不能被点击,默认是yes

    NSString * path=[[NSBundlemainBundle]pathForResource:@"guo" ofType:@"jpg"];//单例类,这种方式拿图片图片不会缓存,效率低,安全性高。

    UIImage *image = [[UIImagealloc]initWithContentsOfFile:path];//读取图片

    UIImageView->UIView;

    imageView.contentMode =UIViewContentModeScaleToFill;//图片内容布局方式;

    imageView.animationImages = birdArr;//把一组图片作为imageView一组动画图片

    imageView.animationDuration = 0.5;//动画持续的时间(秒)

    imageView.animationRepeatCount = 0;//动画重复的次数 0 表示一直重复

    [imageView startAnimating];//启动动画

    [imageView stopAnimating];//停止动画


0 0
原创粉丝点击