UIButton.h

//
//  UIButton.h
//  UIKit
//
//  Copyright (c) 2005-2013, Apple Inc. All rights reserved.
//

@class UIImage, UIFont, UIColor, UIImageView, UILabel;

typedef NS_ENUM(NSInteger, UIButtonType) {
    UIButtonTypeCustom = 0,                         // 無樣式夷恍,用戶調(diào)整
    UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0),  // 系統(tǒng)標(biāo)準(zhǔn)樣式

    UIButtonTypeDetailDisclosure, // 圈圈 i 樣式
    UIButtonTypeInfoLight,        // 圈圈 i 樣式
    UIButtonTypeInfoDark,         // 圈圈 i 樣式
    UIButtonTypeContactAdd,       // 圈圈 + 樣式
    
    UIButtonTypeRoundedRect = UIButtonTypeSystem,   // 淘汰,用 UIButtonTypeSystem 替代
};

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIButton : UIControl <NSCoding> {
  @private // 私有的
    CFMutableDictionaryRef _contentLookup;
    UIEdgeInsets           _contentEdgeInsets;  // 內(nèi)容的內(nèi)邊距
    UIEdgeInsets           _titleEdgeInsets;    // 標(biāo)題的內(nèi)邊距
    UIEdgeInsets           _imageEdgeInsets;    // 圖片的內(nèi)邊距
    
    UIImageView           *_backgroundView;      // 內(nèi)部的背景圖片控件
    UIImageView           *_imageView;           // 內(nèi)部的圖片控件
    UILabel               *_titleView;           // 內(nèi)部的標(biāo)題
    
    BOOL                   _initialized;
    UIControlState         _lastDrawingControlState;
    struct {
        unsigned int reversesTitleShadowWhenHighlighted:1;
        unsigned int adjustsImageWhenHighlighted:1;
        unsigned int adjustsImageWhenDisabled:1;
        unsigned int autosizeToFit:1;
        unsigned int disabledDimsImage:1;
        unsigned int showsTouchWhenHighlighted:1;
        unsigned int buttonType:8;
        unsigned int shouldHandleScrollerMouseEvent:1;
        unsigned int titleFrozen:1;
    } _buttonFlags;
}

+ (id)buttonWithType:(UIButtonType)buttonType;

@property(nonatomic)          UIEdgeInsets contentEdgeInsets UI_APPEARANCE_SELECTOR; // 內(nèi)容縮進(jìn)
@property(nonatomic)          UIEdgeInsets titleEdgeInsets;                // 文字標(biāo)題縮進(jìn)
@property(nonatomic)          BOOL         reversesTitleShadowWhenHighlighted; // 默認(rèn) NO. 高亮?xí)r,陰影反轉(zhuǎn)
@property(nonatomic)          UIEdgeInsets imageEdgeInsets;                // 圖片縮進(jìn)

@property(nonatomic)          BOOL         adjustsImageWhenHighlighted;    // default is YES. if YES, image is drawn darker when highlighted(pressed)
@property(nonatomic)          BOOL         adjustsImageWhenDisabled;       // default is YES. if YES, image is drawn lighter when disabled
@property(nonatomic)          BOOL         showsTouchWhenHighlighted;      // 點(diǎn)擊時(shí)按鈕中間現(xiàn)實(shí)白色的高亮
@property(nonatomic,retain)   UIColor     *tintColor NS_AVAILABLE_IOS(5_0); // The tintColor is inherited through the superview hierarchy. See UIView for more information.
@property(nonatomic,readonly) UIButtonType buttonType;

# 設(shè)置內(nèi)部子控件的屬性
- (void)setTitle:(NSString *)title forState:(UIControlState)state; # 字體
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; #字體顏色
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; # 陰影
- (void)setImage:(UIImage *)image forState:(UIControlState)state;
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (void)setAttributedTitle:(NSAttributedString *)title forState:(UIControlState)state NS_AVAILABLE_IOS(6_0);

# 這些 getters 方法只返回一種狀態(tài)的值
- (NSString *)titleForState:(UIControlState)state;
- (UIColor *)titleColorForState:(UIControlState)state;
- (UIColor *)titleShadowColorForState:(UIControlState)state;
- (UIImage *)imageForState:(UIControlState)state;
- (UIImage *)backgroundImageForState:(UIControlState)state;
- (NSAttributedString *)attributedTitleForState:(UIControlState)state NS_AVAILABLE_IOS(6_0);

# 當(dāng)按鈕的狀態(tài)改變時(shí)向叉,這些值會(huì)自動(dòng)改變邑闲,只有g(shù)et方法斩箫,只讀的
@property(nonatomic,readonly,retain) NSString *currentTitle;             // 可以為空
@property(nonatomic,readonly,retain) UIColor  *currentTitleColor;        // 默認(rèn)是white(1,1) 退腥,不能為空
@property(nonatomic,readonly,retain) UIColor  *currentTitleShadowColor;  // default is white(0,0.5).
@property(nonatomic,readonly,retain) UIImage  *currentImage;             // 可以為空
@property(nonatomic,readonly,retain) UIImage  *currentBackgroundImage;   // 可以為空
@property(nonatomic,readonly,retain) NSAttributedString *currentAttributedTitle NS_AVAILABLE_IOS(6_0); # 可以為空

# return title and image views. will always create them if necessary. always returns nil for system buttons
@property(nonatomic,readonly,retain) UILabel     *titleLabel NS_AVAILABLE_IOS(3_0);
@property(nonatomic,readonly,retain) UIImageView *imageView  NS_AVAILABLE_IOS(3_0);


#pragma - mark 自定義按鈕惕稻,重寫這些方法調(diào)整按鈕內(nèi)部子控件的尺寸
- (CGRect)backgroundRectForBounds:(CGRect)bounds;
- (CGRect)contentRectForBounds:(CGRect)bounds;
- (CGRect)titleRectForContentRect:(CGRect)contentRect;
- (CGRect)imageRectForContentRect:(CGRect)contentRect;

@end

# 已經(jīng)失效
@interface UIButton(UIButtonDeprecated)

@property(nonatomic,retain) UIFont         *font              NS_DEPRECATED_IOS(2_0, 3_0); // 字體
@property(nonatomic)        NSLineBreakMode lineBreakMode     NS_DEPRECATED_IOS(2_0, 3_0); //
@property(nonatomic)        CGSize          titleShadowOffset NS_DEPRECATED_IOS(2_0, 3_0);

@end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末蔗衡,一起剝皮案震驚了整個(gè)濱河市纤虽,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌绞惦,老刑警劉巖逼纸,帶你破解...
    沈念sama閱讀 217,084評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異济蝉,居然都是意外死亡杰刽,警方通過查閱死者的電腦和手機(jī)菠发,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來贺嫂,“玉大人滓鸠,你說我怎么就攤上這事±酝瘢” “怎么了哥力?”我有些...
    開封第一講書人閱讀 163,450評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長墩弯。 經(jīng)常有香客問我吩跋,道長,這世上最難降的妖魔是什么渔工? 我笑而不...
    開封第一講書人閱讀 58,322評(píng)論 1 293
  • 正文 為了忘掉前任锌钮,我火速辦了婚禮,結(jié)果婚禮上引矩,老公的妹妹穿的比我還像新娘梁丘。我一直安慰自己,他們只是感情好旺韭,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,370評(píng)論 6 390
  • 文/花漫 我一把揭開白布氛谜。 她就那樣靜靜地躺著,像睡著了一般区端。 火紅的嫁衣襯著肌膚如雪值漫。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,274評(píng)論 1 300
  • 那天织盼,我揣著相機(jī)與錄音杨何,去河邊找鬼。 笑死沥邻,一個(gè)胖子當(dāng)著我的面吹牛危虱,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播唐全,決...
    沈念sama閱讀 40,126評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼埃跷,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了邮利?” 一聲冷哼從身側(cè)響起弥雹,我...
    開封第一講書人閱讀 38,980評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎近弟,沒想到半個(gè)月后缅糟,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體挺智,經(jīng)...
    沈念sama閱讀 45,414評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡祷愉,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,599評(píng)論 3 334
  • 正文 我和宋清朗相戀三年窗宦,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片二鳄。...
    茶點(diǎn)故事閱讀 39,773評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡赴涵,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出订讼,到底是詐尸還是另有隱情髓窜,我是刑警寧澤,帶...
    沈念sama閱讀 35,470評(píng)論 5 344
  • 正文 年R本政府宣布欺殿,位于F島的核電站寄纵,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏脖苏。R本人自食惡果不足惜程拭,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,080評(píng)論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望棍潘。 院中可真熱鬧恃鞋,春花似錦、人聲如沸亦歉。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,713評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽肴楷。三九已至水由,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間阶祭,已是汗流浹背绷杜。 一陣腳步聲響...
    開封第一講書人閱讀 32,852評(píng)論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留濒募,地道東北人鞭盟。 一個(gè)月前我還...
    沈念sama閱讀 47,865評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像瑰剃,于是被迫代替她去往敵國和親齿诉。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,689評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容