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;
}