您的位置:首页 > 产品设计 > UI/UE

UIButton的简单使用

2014-02-14 15:19 323 查看
UIButton

button.adjustsImageWhenDisabled = NO;  //当设置按钮不可用时,按钮的颜色会变化,此属性来控制这个功能是否开启,设置为NO时,颜色不变

button.adjustsImageWhenHighlighted = NO; //当按钮处于高亮状态时,按钮颜色不变

reversesTitleShadowWhenHighlighted       //当按钮处于高亮状态时,标题的阴影是否改变

showsTouchWhenHighlighted                 //点击按钮时是否让其发光

tintColor                                                //提示的颜色

//设置按钮中的内容里四个边界的距离 四个参数分别代表的是距离上,左,下,右边界的距离,如果本身距边界距离大于参数,则布局不变

button.contentEdgeInsets = UIEdgeInsetsMake(0,10,
0,
0);    

同上

imageEdgeInsets

titleEdgeInsets

//当前按钮的标题,只读方法

currentAttributedTitle  

NSAttributedString *currentAttributedTitle
= button.currentAttributedTitle;  //但是按钮的标题默认为空

currentBackgroundImage    当前按钮的背景,只读

UIImage image = button.currentBackgroundImage;


currentImage     当前按钮的图片,只读


currentTitle  当前标题,只读,反悔类型为NSString


currentTitleColor  只读

titleLabel  只读    显示currentTitle的视图

currentTitleShadowColor 只读




METHOD


- (UIImage *)imageForState:(UIControlState)state
  //返回某个状态下使用的图片

- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state
   设置标题

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
  设置背景图片

-
(void)setImage:(UIImage *)image forState:(UIControlState)state
   设置按钮图片

-
(void)setTitle:(NSString *)title forState:(UIControlState)state
   设置标题

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state 
 设置标题字体

- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state
   设置标题阴影

- (UIColor *)titleColorForState:(UIControlState)state
             返回某个状态下提示的颜色

-
(NSString *)titleForState:(UIControlState)state
                     返回某个状态下的标题

-
(UIColor *)titleShadowColorForState:(UIControlState)state
    返回某个状态下的标题阴影颜色

-
(CGRect)backgroundRectForBounds:(CGRect)bounds
                     返回控件的背景CGRect     bound是接收着的CGRect

-
(CGRect)contentRectForBounds:(CGRect)bounds
                           返回内容的CGRect     bound是接收着的CGRect

-
(CGRect)imageRectForContentRect:(CGRect)contentRect
               返回控件的图片CGRect    contentRect是内容的CGRect

添加点击事件

[button addTarget:self
action:@selector(btnClick:)
forControlEvents:UIControlEventTouchUpInside];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios UIButton