点击某个按钮弹出一个遮罩视图(黑色,透明度0.4),然后在遮罩视图上添加了一个从视图底部动画弹出的视图,弹出视图上有个按钮,点击可以移除遮罩视图和该视图,但是貌似该按钮有点小,不好点,然后我就用UIButton的title偏移量使得按钮的点击范围较大但title文字的位置和大小仍和之前显示一致。 注:布局用的PureLayout这个第三方库。 代码:
//
// ViewController.m
// CaiTest-luckyCoderCai
//
// Created by luckyCoderCai on 16/8/3.
// Copyright © 2016年 luckyCoderCai. All rights reserved.
//
#import "ViewController.h"
#import "PureLayout/PureLayout.h"
@interface ViewController ()
@property (nonatomic, strong) UIButton *testBtn;
@property (nonatomic, strong) UIButton *testButton;
@end
@implementation ViewController
- (UIButton *)testBtn
{
if (!_testBtn) {
_testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_testBtn.backgroundColor = [UIColor purpleColor];
_testBtn.translatesAutoresizingMaskIntoConstraints = NO;
[_testBtn setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
[_testBtn addTarget:self action:@selector(testBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _testBtn;
}
- (UIButton *)testButton
{
if (!_testButton) {
_testButton = [UIButton buttonWithType:UIButtonTypeCustom];
_testButton.backgroundColor = [UIColor purpleColor];
_testButton.translatesAutoresizingMaskIntoConstraints = NO;
[_testButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
[_testButton addTarget:self action:@selector(testButtonAction) forControlEvents:UIControlEventTouchUpInside];
}
return _testButton;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor orangeColor];
[self createUI];
}
- (void)createUI
{
[self.view addSubview:self.testBtn];
[self.testBtn autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:15];
[self.testBtn autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:100];
[self.testBtn autoSetDimensionsToSize:CGSizeMake(16, 16)];
[self.view addSubview:self.testButton];
[self.testButton autoPinEdgeToSuperviewEdge:ALEdgeLeading];
[self.testButton autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:150];
[self.testButton autoSetDimensionsToSize:CGSizeMake(31 + 15, 31)];
[self.testButton setImageEdgeInsets:UIEdgeInsetsMake(15/2.0, 15, 15/2.0, 15)];
}
#pragma mark -
- (void)testBtnAction
{
NSLog(@"---testBtn");
}
- (void)testButtonAction
{
NSLog(@"---testButton");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
复制代码
图: