Skip to content

Commit 27af4f7

Browse files
committed
1
测试
1 parent 2cf516c commit 27af4f7

40 files changed

Lines changed: 1524 additions & 21 deletions

JCKit/Chain/UIView+JCChain.h

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
//
2+
// UIView+JCChain.h
3+
// JCKitDemo
4+
//
5+
// Created by molin.JC on 2017/12/1.
6+
// Copyright © 2017年 molin. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface UIView (JCChain)
12+
+ (instancetype)init;
13+
@property (nonatomic, weak, readonly) UIView *(^setBackgroundColor)(UIColor *backgroundColor);
14+
@end
15+
16+
@interface UILabel (JCChain)
17+
@property (nonatomic, weak, readonly) UILabel *(^setBackgroundColor)(UIColor *backgroundColor);
18+
@property (nonatomic, weak, readonly) UILabel *(^setText)(NSString *text);
19+
@property (nonatomic, weak, readonly) UILabel *(^setFont)(UIFont *font);
20+
@property (nonatomic, weak, readonly) UILabel *(^setTextColor)(UIColor *textColor);
21+
@property (nonatomic, weak, readonly) UILabel *(^setTextAlignment)(NSTextAlignment textAlignment);
22+
@property (nonatomic, weak, readonly) UILabel *(^setNumberOfLines)(NSInteger numberOfLines);
23+
@property (nonatomic, weak, readonly) UILabel *(^setAttributedText)(NSAttributedString *attributedText);
24+
@end
25+
26+
@interface UITextField (JCChain)
27+
@property (nonatomic, weak, readonly) UITextField *(^setDelegate)(id<UITextFieldDelegate>);
28+
@property (nonatomic, weak, readonly) UITextField *(^setBackgroundColor)(UIColor *backgroundColor);
29+
@property (nonatomic, weak, readonly) UITextField *(^setText)(NSString *text);
30+
@property (nonatomic, weak, readonly) UITextField *(^setFont)(UIFont *font);
31+
@property (nonatomic, weak, readonly) UITextField *(^setTextColor)(UIColor *textColor);
32+
@property (nonatomic, weak, readonly) UITextField *(^setTextAlignment)(NSTextAlignment textAlignment);
33+
@property (nonatomic, weak, readonly) UITextField *(^setAttributedText)(NSAttributedString *attributedText);
34+
@property (nonatomic, weak, readonly) UITextField *(^setPlaceholder)(NSString *placeholder);
35+
@property (nonatomic, weak, readonly) UITextField *(^setAttributedPlaceholder)(NSAttributedString *attributedPlaceholder);
36+
@property (nonatomic, weak, readonly) UITextField *(^setDefaultTextAttributes)(NSDictionary *defaultTextAttributes);
37+
@property (nonatomic, weak, readonly) UITextField *(^setBorderStyle)(UITextBorderStyle borderStyle);
38+
@property (nonatomic, weak, readonly) UITextField *(^setClearButtonMode)(UITextFieldViewMode clearButtonMode);
39+
@property (nonatomic, weak, readonly) UITextField *(^setKeyboardType)(UIKeyboardType keyboardType);
40+
@property (nonatomic, weak, readonly) UITextField *(^setReturnKeyType)(UIReturnKeyType returnKeyType);
41+
@property (nonatomic, weak, readonly) UITextField *(^setKeyboardAppearance)(UIKeyboardAppearance keyboardAppearance);
42+
@property (nonatomic, weak, readonly) UITextField *(^setInputView)(UIView *inputView);
43+
@property (nonatomic, weak, readonly) UITextField *(^setInputAccessoryView)(UIView *inputAccessoryView);
44+
@end
45+
46+
@interface UITextView (JCChain)
47+
@property (nonatomic, weak, readonly) UITextView *(^setDelegate)(id<UITextViewDelegate>);
48+
@property (nonatomic, weak, readonly) UITextView *(^setBackgroundColor)(UIColor *backgroundColor);
49+
@property (nonatomic, weak, readonly) UITextView *(^setText)(NSString *text);
50+
@property (nonatomic, weak, readonly) UITextView *(^setFont)(UIFont *font);
51+
@property (nonatomic, weak, readonly) UITextView *(^setTextColor)(UIColor *textColor);
52+
@property (nonatomic, weak, readonly) UITextView *(^setTextAlignment)(NSTextAlignment textAlignment);
53+
@property (nonatomic, weak, readonly) UITextView *(^setAttributedText)(NSAttributedString *attributedText);
54+
@property (nonatomic, weak, readonly) UITextView *(^setLinkTextAttributes)(NSDictionary *linkTextAttributes);
55+
@property (nonatomic, weak, readonly) UITextView *(^setKeyboardType)(UIKeyboardType keyboardType);
56+
@property (nonatomic, weak, readonly) UITextView *(^setReturnKeyType)(UIReturnKeyType returnKeyType);
57+
@property (nonatomic, weak, readonly) UITextView *(^setKeyboardAppearance)(UIKeyboardAppearance keyboardAppearance);
58+
@property (nonatomic, weak, readonly) UITextView *(^setInputView)(UIView *inputView);
59+
@property (nonatomic, weak, readonly) UITextView *(^setInputAccessoryView)(UIView *inputAccessoryView);
60+
@end
61+
62+
@interface UIControl (JCChain)
63+
@property (nonatomic, weak, readonly) UIControl *(^setBackgroundColor)(UIColor *backgroundColor);
64+
@property (nonatomic, weak, readonly) UIControl *(^addTarget)(id target, SEL action, UIControlEvents event);
65+
@end
66+
67+
@interface UIButton (JCChain)
68+
@property (class, nonatomic, readonly) UIButton *(^buttonType)(UIButtonType);
69+
@property (nonatomic, weak, readonly) UIButton *(^setBackgroundColor)(UIColor *backgroundColor);
70+
@property (nonatomic, weak, readonly) UIButton *(^addTarget)(id target, SEL action, UIControlEvents event);
71+
/** 设置标题,状态默认UIControlStateNormal */
72+
@property (nonatomic, weak, readonly) UIButton *(^setTitle)(NSString *);
73+
/** 设置标题和状态 */
74+
@property (nonatomic, weak, readonly) UIButton *(^setTitleOrState)(NSString *, UIControlState);
75+
/** 设置标题颜色 */
76+
@property (nonatomic, weak, readonly) UIButton *(^setTitleColor)(UIColor *);
77+
/** 设置标题颜色和状态 */
78+
@property (nonatomic, weak, readonly) UIButton *(^setTitleColorOrState)(UIColor *, UIControlState);
79+
/** 设置字体大小 */
80+
@property (nonatomic, weak, readonly) UIButton *(^setFont)(UIFont *);
81+
/** 设置标题富文本的样式 */
82+
@property (nonatomic, weak, readonly) UIButton *(^setAttributedTitle)(NSAttributedString *);
83+
/** 设置标题富文本的样式和状态 */
84+
@property (nonatomic, weak, readonly) UIButton *(^setAttributedTitleOrState)(NSAttributedString *, UIControlState);
85+
/** 设置图片 */
86+
@property (nonatomic, weak, readonly) UIButton *(^setImage)(UIImage *);
87+
/** 设置图片和状态 */
88+
@property (nonatomic, weak, readonly) UIButton *(^setImageOrState)(UIImage *, UIControlState);
89+
/** 设置背景图片 */
90+
@property (nonatomic, weak, readonly) UIButton *(^setBackgroundImage)(UIImage *);
91+
/** 设置背景图片和状态 */
92+
@property (nonatomic, weak, readonly) UIButton *(^setBackgroundImageOrState)(UIImage *, UIControlState);
93+
@end
94+
95+
@interface UIImageView (JCChain)
96+
@property (class, nonatomic, readonly) UIImageView *(^initWithImage)(UIImage *);
97+
@property (nonatomic, weak, readonly) UIImageView *(^setBackgroundColor)(UIColor *backgroundColor);
98+
@property (nonatomic, weak, readonly) UIImageView *(^setImage)(UIImage *);
99+
@end
100+
101+
@interface UIScrollView (JCChain)
102+
@property (nonatomic, weak, readonly) UIScrollView *(^setDelegate)(id<UIScrollViewDelegate>);
103+
@property (nonatomic, weak, readonly) UIScrollView *(^setBackgroundColor)(UIColor *backgroundColor);
104+
@property (nonatomic, weak, readonly) UIScrollView *(^setOffset)(CGPoint);
105+
@property (nonatomic, weak, readonly) UIScrollView *(^setOffsetX)(CGFloat);
106+
@property (nonatomic, weak, readonly) UIScrollView *(^setOffsetY)(CGFloat);
107+
@property (nonatomic, weak, readonly) UIScrollView *(^setContentSize)(CGSize);
108+
@property (nonatomic, weak, readonly) UIScrollView *(^setContentWidth)(CGFloat);
109+
@property (nonatomic, weak, readonly) UIScrollView *(^setContentHeight)(CGFloat);
110+
@property (nonatomic, weak, readonly) UIScrollView *(^setInset)(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right);
111+
@property (nonatomic, weak, readonly) UIScrollView *(^setBounces)(BOOL);
112+
@property (nonatomic, weak, readonly) UIScrollView *(^setPagingEnabled)(BOOL);
113+
@property (nonatomic, weak, readonly) UIScrollView *(^setScrollEnabled)(BOOL);
114+
@property (nonatomic, weak, readonly) UIScrollView *(^setHorizontalScrollIndicator)(BOOL);
115+
@property (nonatomic, weak, readonly) UIScrollView *(^setVerticalScrollIndicator)(BOOL);
116+
@end
117+
118+
@interface UITableView (JCChain)
119+
@property (class, nonatomic, readonly) UITableView *(^initWithStyle)(UITableViewStyle);
120+
@property (nonatomic, weak, readonly) UITableView *(^setDelegate)(id<UITableViewDelegate>);
121+
@property (nonatomic, weak, readonly) UITableView *(^setDataSource)(id<UITableViewDataSource>);
122+
@property (nonatomic, weak, readonly) UITableView *(^setRowHeight)(CGFloat);
123+
@property (nonatomic, weak, readonly) UITableView *(^setBackgroundColor)(UIColor *backgroundColor);
124+
@property (nonatomic, weak, readonly) UITableView *(^setSeparatorStyle)(UITableViewCellSeparatorStyle);
125+
@property (nonatomic, weak, readonly) UITableView *(^setSeparatorColor)(UIColor *);
126+
@property (nonatomic, weak, readonly) UITableView *(^setTableHeaderView)(UIView *);
127+
@property (nonatomic, weak, readonly) UITableView *(^setTableFooterView)(UIView *);
128+
@end
129+
130+
@interface UICollectionView (JCChain)
131+
@property (class, nonatomic, readonly) UICollectionView *(^initWithLayout)(UICollectionViewLayout *);
132+
@property (nonatomic, weak, readonly) UICollectionView *(^setDelegate)(id<UICollectionViewDelegate>);
133+
@property (nonatomic, weak, readonly) UICollectionView *(^setDataSource)(id<UICollectionViewDataSource>);
134+
@property (nonatomic, weak, readonly) UICollectionView *(^setBackgroundColor)(UIColor *backgroundColor);
135+
@end
136+
137+
@interface CALayer (JCChain)
138+
@property (nonatomic, weak, readonly) CALayer *(^setBackgroundColor)(CGColorRef);
139+
@property (nonatomic, weak, readonly) CALayer *(^setCornerRadius)(CGFloat);
140+
@property (nonatomic, weak, readonly) CALayer *(^setBorderWidth)(CGFloat);
141+
@property (nonatomic, weak, readonly) CALayer *(^setBorderColor)(CGColorRef);
142+
@end

JCKit/Chain/UIView+JCChain.m

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
//
2+
// UIView+JCChain.m
3+
// JCKitDemo
4+
//
5+
// Created by molin.JC on 2017/12/1.
6+
// Copyright © 2017年 molin. All rights reserved.
7+
//
8+
9+
#import "UIView+JCChain.h"
10+
11+
#define _Chain_set(Cla, p, sel, r) \
12+
- (Cla *(^)(r))sel { return ^(r p){self.p = p; return self;};}
13+
14+
15+
@implementation UIView (JCChain)
16+
17+
+ (instancetype)init {
18+
return [[self alloc] init];
19+
}
20+
21+
_Chain_set(UIView, backgroundColor, setBackgroundColor, UIColor *)
22+
@end
23+
24+
@implementation UILabel (JCChain)
25+
_Chain_set(UILabel, backgroundColor, setBackgroundColor, UIColor *)
26+
_Chain_set(UILabel, text, setText, NSString *)
27+
_Chain_set(UILabel, font, setFont, UIFont *)
28+
_Chain_set(UILabel, textColor, setTextColor, UIColor *)
29+
_Chain_set(UILabel, textAlignment, setTextAlignment, NSTextAlignment)
30+
_Chain_set(UILabel, numberOfLines, setNumberOfLines, NSInteger)
31+
_Chain_set(UILabel, attributedText, setAttributedText, NSAttributedString *)
32+
@end
33+
34+
@implementation UITextField (JCChain)
35+
_Chain_set(UITextField, delegate, setDelegate, id<UITextFieldDelegate>)
36+
_Chain_set(UITextField, backgroundColor, setBackgroundColor, UIColor *)
37+
_Chain_set(UITextField, text, setText, NSString *)
38+
_Chain_set(UITextField, font, setFont, UIFont *)
39+
_Chain_set(UITextField, textColor, setTextColor, UIColor *)
40+
_Chain_set(UITextField, textAlignment, setTextAlignment, NSTextAlignment)
41+
_Chain_set(UITextField, attributedText, setAttributedText, NSAttributedString *)
42+
_Chain_set(UITextField, placeholder, setPlaceholder, NSString *)
43+
_Chain_set(UITextField, attributedPlaceholder, setAttributedPlaceholder, NSAttributedString *)
44+
_Chain_set(UITextField, defaultTextAttributes, setDefaultTextAttributes, NSDictionary *)
45+
_Chain_set(UITextField, borderStyle, setBorderStyle, UITextBorderStyle)
46+
_Chain_set(UITextField, clearButtonMode, setClearButtonMode, UITextFieldViewMode)
47+
_Chain_set(UITextField, keyboardType, setKeyboardType, UIKeyboardType)
48+
_Chain_set(UITextField, returnKeyType, setReturnKeyType, UIReturnKeyType)
49+
_Chain_set(UITextField, keyboardAppearance, setKeyboardAppearance, UIKeyboardAppearance)
50+
_Chain_set(UITextField, inputView, setInputView, UIView *)
51+
_Chain_set(UITextField, inputAccessoryView, setInputAccessoryView, UIView *)
52+
@end
53+
54+
@implementation UITextView (JCChain)
55+
_Chain_set(UITextView, delegate, setDelegate, id<UITextViewDelegate>)
56+
_Chain_set(UITextView, backgroundColor, setBackgroundColor, UIColor *)
57+
_Chain_set(UITextView, text, setText, NSString *)
58+
_Chain_set(UITextView, font, setFont, UIFont *)
59+
_Chain_set(UITextView, textColor, setTextColor, UIColor *)
60+
_Chain_set(UITextView, textAlignment, setTextAlignment, NSTextAlignment)
61+
_Chain_set(UITextView, attributedText, setAttributedText, NSAttributedString *)
62+
_Chain_set(UITextView, linkTextAttributes, setLinkTextAttributes, NSDictionary *)
63+
_Chain_set(UITextView, keyboardType, setKeyboardType, UIKeyboardType)
64+
_Chain_set(UITextView, returnKeyType, setReturnKeyType, UIReturnKeyType)
65+
_Chain_set(UITextView, keyboardAppearance, setKeyboardAppearance, UIKeyboardAppearance)
66+
_Chain_set(UITextView, inputView, setInputView, UIView *)
67+
_Chain_set(UITextView, inputAccessoryView, setInputAccessoryView, UIView *)
68+
@end
69+
70+
@implementation UIControl (JCChain)
71+
_Chain_set(UIControl, backgroundColor, setBackgroundColor, UIColor *)
72+
73+
- (UIControl *(^)(id, SEL, UIControlEvents))addTarget {
74+
return ^(id target, SEL action, UIControlEvents event) {
75+
[self addTarget:target action:action forControlEvents:event]; return self;
76+
};
77+
}
78+
@end
79+
80+
@implementation UIButton (JCChain)
81+
82+
+ (UIButton *(^)(UIButtonType))buttonType {
83+
return ^(UIButtonType type) {
84+
return [UIButton buttonWithType:type];
85+
};
86+
}
87+
88+
- (UIButton *(^)(id, SEL, UIControlEvents))addTarget {
89+
return ^(id target, SEL action, UIControlEvents event) {
90+
[self addTarget:target action:action forControlEvents:event]; return self;
91+
};
92+
}
93+
94+
- (UIButton *(^)(UIFont *))setFont {
95+
return ^(UIFont *font) { self.titleLabel.font = font; return self; };
96+
}
97+
98+
#define _Chain_buttonSet(sel, r) \
99+
- (UIButton *(^)(r, UIControlState))sel##OrState {return ^(r p, UIControlState state){[self sel:p forState:state]; return self;}; } \
100+
- (UIButton *(^)(r))sel {return ^(r p){self.sel##OrState(p, UIControlStateNormal); return self;};}
101+
102+
_Chain_buttonSet(setTitle, NSString *)
103+
_Chain_buttonSet(setTitleColor, UIColor *)
104+
_Chain_buttonSet(setAttributedTitle, NSAttributedString *)
105+
_Chain_buttonSet(setImage, UIImage *)
106+
_Chain_buttonSet(setBackgroundImage, UIImage *)
107+
@end
108+
109+
@implementation UIImageView (JCChain)
110+
111+
+ (UIImageView *(^)(UIImage *))initWithImage {
112+
return ^(UIImage *image) { return [[UIImageView alloc] initWithImage:image]; };
113+
}
114+
_Chain_set(UIImageView, backgroundColor, setBackgroundColor, UIColor *)
115+
_Chain_set(UIImageView, image, setImage, UIImage *)
116+
@end
117+
118+
@implementation UIScrollView (JCChain)
119+
_Chain_set(UIScrollView, delegate, setDelegate, id<UIScrollViewDelegate>)
120+
_Chain_set(UIScrollView, backgroundColor, setBackgroundColor, UIColor *)
121+
_Chain_set(UIScrollView, contentOffset, setOffset, CGPoint)
122+
_Chain_set(UIScrollView, contentSize, setContentSize, CGSize)
123+
_Chain_set(UIScrollView, bounces, setBounces, BOOL)
124+
_Chain_set(UIScrollView, pagingEnabled, setPagingEnabled, BOOL)
125+
_Chain_set(UIScrollView, scrollEnabled, setScrollEnabled, BOOL)
126+
_Chain_set(UIScrollView, showsHorizontalScrollIndicator, setHorizontalScrollIndicator, BOOL)
127+
_Chain_set(UIScrollView, showsVerticalScrollIndicator, setVerticalScrollIndicator, BOOL)
128+
129+
- (UIScrollView *(^)(CGFloat))setOffsetX {
130+
return ^(CGFloat x) {
131+
self.contentOffset = CGPointMake(x, self.contentOffset.y);
132+
return self;
133+
};
134+
}
135+
136+
- (UIScrollView *(^)(CGFloat))setOffsetY {
137+
return ^(CGFloat y) {
138+
self.contentOffset = CGPointMake(self.contentOffset.x, y);
139+
return self;
140+
};
141+
}
142+
143+
- (UIScrollView *(^)(CGFloat))setContentWidth {
144+
return ^(CGFloat width) {
145+
self.contentSize = CGSizeMake(width, self.contentSize.height);
146+
return self;
147+
};
148+
}
149+
150+
- (UIScrollView *(^)(CGFloat))setContentHeight {
151+
return ^(CGFloat height) {
152+
self.contentSize = CGSizeMake(self.contentSize.width, height);
153+
return self;
154+
};
155+
}
156+
157+
- (UIScrollView *(^)(CGFloat, CGFloat, CGFloat, CGFloat))setInset {
158+
return ^(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {
159+
self.contentInset = UIEdgeInsetsMake(top, left, bottom, right);
160+
return self;
161+
};
162+
}
163+
164+
@end
165+
166+
@implementation UITableView (JCChain)
167+
168+
+ (UITableView *(^)(UITableViewStyle))initWithStyle {
169+
return ^(UITableViewStyle style) { return [[UITableView alloc] initWithFrame:CGRectZero style:style];};
170+
}
171+
_Chain_set(UITableView, delegate, setDelegate, id<UITableViewDelegate>)
172+
_Chain_set(UITableView, dataSource, setDataSource, id<UITableViewDataSource>)
173+
_Chain_set(UITableView, rowHeight, setRowHeight, CGFloat)
174+
_Chain_set(UITableView, backgroundColor, setBackgroundColor, UIColor *)
175+
_Chain_set(UITableView, separatorStyle, setSeparatorStyle, UITableViewCellSeparatorStyle)
176+
_Chain_set(UITableView, separatorColor, setSeparatorColor, UIColor *)
177+
_Chain_set(UITableView, tableHeaderView, setTableHeaderView, UIView *)
178+
_Chain_set(UITableView, tableFooterView, setTableFooterView, UIView *)
179+
@end
180+
181+
@implementation UICollectionView (JCChain)
182+
183+
+ (UICollectionView *(^)(UICollectionViewLayout *))initWithLayout {
184+
return ^(UICollectionViewLayout *layout) { return [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; };
185+
}
186+
_Chain_set(UICollectionView, delegate, setDelegate, id<UICollectionViewDelegate>)
187+
_Chain_set(UICollectionView, dataSource, setDataSource, id<UICollectionViewDataSource>)
188+
_Chain_set(UICollectionView, backgroundColor, setBackgroundColor, UIColor *)
189+
@end
190+
191+
@implementation CALayer (JCChain)
192+
_Chain_set(CALayer, backgroundColor, setBackgroundColor, CGColorRef)
193+
_Chain_set(CALayer, cornerRadius, setCornerRadius, CGFloat)
194+
_Chain_set(CALayer, borderWidth, setBorderWidth, CGFloat)
195+
_Chain_set(CALayer, borderColor, setBorderColor, CGColorRef)
196+
@end

0 commit comments

Comments
 (0)