1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// ScreeningButton.m
// Lighting
//
// Created by 曹云霄 on 16/5/13.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "ScreeningButton.h"
@implementation ScreeningButton
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.titleLabel.font = [UIFont systemFontOfSize:13];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
[self setImage:TCImage(@"down_arr") forState:UIControlStateNormal];
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 10;
self.backgroundColor = RGB(131, 131, 131,1);
}
return self;
}
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
return CGRectMake((self.frame.size.width-[self ReturnCGsize:self.currentTitle].width)/2, -2, [self ReturnCGsize:self.currentTitle].width, 35);
}
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
return CGRectMake((self.frame.size.width-[self ReturnCGsize:self.currentTitle].width)/2+[self ReturnCGsize:self.currentTitle].width, (self.frame.size.height-6)/2, 11, 6);
}
- (CGSize)ReturnCGsize:(NSString *)string
{
CGSize S = [string boundingRectWithSize:CGSizeMake(999, 35) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]} context:nil].size;
return S;
}
@end