开发者

ios manipulating a views elements programmatically

I want to change the hidden property to some of my elements programmatically based on button click. In javascript I woul开发者_StackOverflow社区d do document.getElementById('element').display = 'block'. Is there a way of doing this is iOS something like: self.'element'.hidden = NO;


UIView has a boolean property called hidden, which is NO by default, you can set it to YES to hide your view. To retrieve views, is it possible to assign tags, which are merely integers (default 0):

[myView setTag:10];

so..

[[myParentView viewWithTag:10] setHidden:YES];

This is pretty similar to js, otherwise you can iterate over subviews:

NSArray *viewsArray = [parentView subviews];

for (UIView *view in viewsArray) {
   // ...
}


Any UIView subclass (e.g. UIButton, UILabel etc.) has a 'hidden' property. Set this to YES of NO to show and hide the view. e.g.

myButton.hidden = NO;
myLabel.hidden = YES;

Take a look at the documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜