關於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等都是一個快速訪問的方法。