IOS中,Button的currentTitle和titleLabel.text的使用

關於Button的兩個property使用,官方參考如下:
// these are the values that will be used for the current state. you can also use these for overrides. a heuristic will be used to
// determine what image to choose based on the explict states set. For example, the ‘normal’ state value will be used for all states
// that don’t have their own image defined.

@property(nonatomic,readonly,retain) NSString *currentTitle;
// normal/highlighted/selected/disabled. can return nil

// 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);

其實currentTitle是對titleLable.text 的一個快速訪問。
currentTitle只讀
UIButton *but=[UIButton buttonWithType:UIButtonTypeCustom];
[but setTitle:@”測試一下” forState:UIControlStateNormal];
NSLog(@”%@”,but.currentTitle);
NSLog(@”%@”,but.titleLabel.text);

打印出的結果一樣,同理,currentImage,currentBackgroundImage等都是一個快速訪問的方法。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章