码迷,mamicode.com
首页 > 移动开发 > 详细

IOS UIButton常用属性

时间:2017-03-03 14:59:20      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:内容模型   ted   UI   enter   uibutton   uiimage   边框   target   tom   

 

 

   
        //1.添加按钮
        UIButton *nameView=[UIButton buttonWithType:UIButtonTypeCustom];
        //nameView.backgroundColor=[UIColor redColor];
        [nameView setBackgroundImage:[UIImage imageNamed:@"buddy_header_bg"] forState:UIControlStateNormal];
        
        [nameView setBackgroundImage:[UIImage imageNamed:@"buddy_header_bg_highlighted"] forState:UIControlStateHighlighted];
        
        //设置按钮内部的左边箭头图片
        [nameView setImage:[UIImage imageNamed:@"buddy_header_arrow"] forState:UIControlStateNormal];
        [nameView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
//        //设置按钮的内容左对齐
//        nameView.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        // 设置按钮的内容左对齐
        nameView.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        
        //设置按钮的内边距
        nameView.titleEdgeInsets=UIEdgeInsetsMake(0, 10, 0, 0);
        nameView.contentEdgeInsets=UIEdgeInsetsMake(0, 10, 0, 0);
                [nameView addTarget:self action:@selector(nameViewClick) forControlEvents:UIControlEventTouchUpInside];
        
        //设置按钮内部的imageView的内容模型为居中
        nameView.imageView.contentMode=UIViewContentModeCenter;
        
        //超出边框的内容不需要裁剪
        nameView.imageView.clipsToBounds=NO;
        
        [self.contentView addSubview:nameView];
        self.nameView=nameView;
        

 

IOS UIButton常用属性

标签:内容模型   ted   UI   enter   uibutton   uiimage   边框   target   tom   

原文地址:http://www.cnblogs.com/liuwj/p/6496647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!