1.说明
使用UIView的属性hidden隐藏指定的区域,属性hidden值为YES时隐藏UIView,属性hidden值为NO时显示UIView
2.实例
起:点击按钮
终:实现文本隐藏和文本显示切换
.h
#import <UIKit/UIKit.h>
@interface UIKitPrjFrame : UIViewController {
@private
UILabel * _label;
}
@end
.m
#import "UIKitPrjFrame.h"
@interface UIKitPrjFrame ()
@end
@implementation UIKitPrjFrame
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blackColor];
_label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
_label.textAlignment = NSTextAlignmentCenter;
_label.backgroundColor = [UIColor blackColor];
_label.textColor = [UIColor whiteColor];
_label.text = @"Im' here";
[self.view addSubview:_label];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0, 0, 100, 40);
CGPoint newPoint = self.view.center;
newPoint.y = self.view.frame.size.height - 70;
button.center = newPoint;
[button setTitle:@"点击" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonDidPush) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)buttonDidPush {
_label.hidden = !_label.hidden;
}
本博客展示了如何通过按钮点击操作,在iOS应用中实现UILabel文本的隐藏与显示功能,涉及UIView的hidden属性的应用。
2190

被折叠的 条评论
为什么被折叠?



