-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIView+WRBQuickControl.m
122 lines (109 loc) · 4.31 KB
/
UIView+WRBQuickControl.m
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// UIView+WRBQuickControl.m
// AVAudioPlayerDemo
//
// Created by qianfeng on 15/9/14.
// Copyright (c) 2015年 quiet. All rights reserved.
//
#import "UIView+WRBQuickControl.h"
@implementation UIView (WRBQuickControl)
//创建系统按钮
-(UIButton *)addSystemButtonWithFrame:(CGRect)frame
title:(NSString *)titile
action:(void(^)(WRBButton *button))action
{
WRBButton *button = [WRBButton buttonWithType:UIButtonTypeSystem];
button.frame = frame;
[button setTitle:titile forState:UIControlStateNormal];
button.action = action;
[self addSubview:button];
return button;
}
+(UIButton *)systemButtonWithFrame:(CGRect)frame
title:(NSString *)titile
action:(void(^)(WRBButton *button))action
{
WRBButton *button = [WRBButton buttonWithType:UIButtonTypeSystem];
button.frame = frame;
[button setTitle:titile forState:UIControlStateNormal];
button.action = action;
return button;
}
//创建图片按钮
-(UIButton *)addImageButtonWithFrame:(CGRect)frame
title:(NSString *)titile
image:(NSString *)image
backgroundImage:(NSString *)backgroundImage
action:(void(^)(WRBButton *button))action
{
WRBButton *button = [WRBButton buttonWithType:UIButtonTypeCustom];
button.frame = frame;
[button setTitle:titile forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:backgroundImage] forState:UIControlStateNormal];
button.action = action;
[self addSubview:button];
return button;
}
+(UIButton *)imageButtonWithFrame:(CGRect)frame
title:(NSString *)titile
image:(NSString *)image
backgroundImage:(NSString *)backgroundImage
action:(void(^)(WRBButton *button))action
{
WRBButton *button = [WRBButton buttonWithType:UIButtonTypeCustom];
button.frame = frame;
[button setTitle:titile forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:backgroundImage] forState:UIControlStateNormal];
button.action = action;
return button;
}
//创建label
-(UILabel *)addLabelWithFrame:(CGRect)frame
title:(NSString *)title
{
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.text = title;
[self addSubview:label];
return label;
}
//创建imageView
-(UIImageView *)addImageViewWithFrame:(CGRect)frame
image:(NSString *)image
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = [UIImage imageNamed:image];
[self addSubview:imageView];
return imageView;
}
//创建textfiled
-(UITextField *)addTextFieldWithFrame:(CGRect)frame
placeholder:(NSString *)holder
borderStyle:(UITextBorderStyle)style
delegate:(id)delegate
{
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
textField.placeholder = holder;
textField.borderStyle = style;
textField.delegate = delegate;
[self addSubview:textField];
return textField;
}
/** 创建左边图片,中间文字,输入框的控件,类似于微信的输入框 */
-(id)addInputTextFieldWithFrame:(CGRect)frame andBackgroundImage:(NSString *)backImage andImage:(NSString *)image andMessage:(NSString *)message
{
UIImageView *imageView =[[UIImageView alloc]initWithFrame:frame];
imageView.image = [UIImage imageNamed:backImage];
imageView.userInteractionEnabled = YES;
[self addSubview:imageView];
UIImageView *leftImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 5, 20, 20)];
leftImage.center = CGPointMake(30, frame.size.height/2);
leftImage.image = [UIImage imageNamed:image];
[imageView addSubview:leftImage];
UITextField *rightTextField = [[UITextField alloc]initWithFrame:CGRectMake(60, 0,frame.size.width-50,frame.size.height)];
rightTextField.placeholder = message;
[imageView addSubview:rightTextField];
return imageView;
}
@end