繼承自UIView,兩個方法:
// 初始化
- (instancetype)init {
if (self = [super init]) {
self.backgroundColor = [UIColor blackColor];
self.layer.cornerRadius = 5.0f;
self.layer.masksToBounds = YES;
self.remarksLabel = [[UILabel alloc] init];
self.remarksLabel.font = [UIFont boldSystemFontOfSize:15];
self.remarksLabel.textColor = [UIColor yellowColor];
self.remarksLabel.textAlignment =1;
self.remarksLabel.backgroundColor = [UIColor clearColor];
[self addSubview:self.remarksLabel];
}
return self;
}
// 顯示提示框
- (void)showMessage:(NSString *)message {
self.alpha =1.0;
CGRect mainScreenRect = [UIScreen mainScreen].bounds;
CGSize labelSize = [message sizeWithAttributes:@{NSFontAttributeName:self.remarksLabel.font}];
self.remarksLabel.frame =CGRectMake(10,5, labelSize.width, labelSize.height);
self.remarksLabel.text = message;
self.frame =CGRectMake((mainScreenRect.size.width - labelSize.width)/2, mainScreenRect.size.height/1.25, labelSize.width + 20, labelSize.height + 10);
[UIView animateWithDuration:3 animations:^{
self.alpha =0;
} completion:^(BOOL finished) {
}];
}