我想限制現有組件的某些屬性。如何限制iPhone中UIbutton屬性的訪問?
下面是示例代碼,
UIButton *customBtn;
property (nonatomic, strong) UIButton *customBtn;
@synthesize customBtn;
這是我實現,
customBtn= [UIButton buttonWithType:UIButtonTypeCustom];
customBtn= setImage:[UIImage imageNamed"radio_button_noraml.png"] forState:UIControlStateNormal];
customBtn= setImage:[UIImage imageNamed"radio_button_acitve.png"] forState:UIControlStateSelected];
customBtn = CGRectMake(5, 30, 20, 20); notsupport = [[UILabel alloc]initWithFrame:CGRectMake(25, 30, 290, 20)];
[customBtn addTargetelf actionselector(MyAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customBtn];
在我的視圖控制器,我可以使用customBtn訪問的UIButton的所有財產。
myClass.customBtn.backGroundcolor = [UIColor blackColor];
但我想限制按鈕屬性的訪問,例如我想要訪問propertybackground顏色和alpha值,我不想訪問的屬性的其餘部分。
所以請幫助我。
謝謝!
在途中可能是子類。 –
簡單...不寫代碼的所有其他財產.... hihihihihihih ...:P – Rajneesh071
你不應該依靠任何方法是不可調用的。方法都是公開的,你可以做的就是把它們放在類擴展或私有頭文件中,這樣當你用代碼調用它們時會得到一個警告......但是在運行時它仍然是遊戲......你有用ivars稍微控制範圍...但是你通常不希望其他類達到你的ivars(爲了封裝起見) –