├── .gitignore ├── LICENSE ├── README.md ├── XRCategory.podspec ├── XRCategory ├── NSArray+XRCategory.h ├── NSArray+XRCategory.m ├── NSDictionary+XRCategory.h ├── NSDictionary+XRCategory.m ├── NSObject+XRCategory.h ├── NSObject+XRCategory.m ├── NSString+XRCategory.h ├── NSString+XRCategory.m ├── UIButton+XRCategory.h ├── UIButton+XRCategory.m ├── UIControl+XRCategory.h ├── UIControl+XRCategory.m ├── UIImageView+XRCategory.h ├── UIImageView+XRCategory.m ├── UILabel+XRCategory.h ├── UILabel+XRCategory.m ├── UIScrollView+XRCategory.h ├── UIScrollView+XRCategory.m ├── UITableView+XRCategory.h ├── UITableView+XRCategory.m ├── UITextField+XRCategory.h ├── UITextField+XRCategory.m ├── UITextView+XRCategory.h ├── UITextView+XRCategory.m ├── UIView+XRCategory.h ├── UIView+XRCategory.m └── XRCategory.h └── XRCategoryDemo ├── XRCategoryDemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── XRCategoryDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json └── icon.imageset │ ├── 2bumen.png │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── Person.h ├── Person.m ├── ViewController.h ├── ViewController.m ├── XRCategory ├── NSArray+XRCategory.h ├── NSArray+XRCategory.m ├── NSDictionary+XRCategory.h ├── NSDictionary+XRCategory.m ├── NSObject+XRCategory.h ├── NSObject+XRCategory.m ├── NSString+XRCategory.h ├── NSString+XRCategory.m ├── UIButton+XRCategory.h ├── UIButton+XRCategory.m ├── UIControl+XRCategory.h ├── UIControl+XRCategory.m ├── UIImageView+XRCategory.h ├── UIImageView+XRCategory.m ├── UILabel+XRCategory.h ├── UILabel+XRCategory.m ├── UIScrollView+XRCategory.h ├── UIScrollView+XRCategory.m ├── UITableView+XRCategory.h ├── UITableView+XRCategory.m ├── UITextField+XRCategory.h ├── UITextField+XRCategory.m ├── UITextView+XRCategory.h ├── UITextView+XRCategory.m ├── UIView+XRCategory.h ├── UIView+XRCategory.m └── XRCategory.h └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 codingZero 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XRCategory 2 | a powerful category,make development easier 3 | 4 | 一个强大的分类,让开发更简单 5 | 6 | --------- 7 | # 功能 8 | ###### 以前你可能这样写代码 9 | ![](http://upload-images.jianshu.io/upload_images/1429074-32e830885c37cdbc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 10 | ###### 现在你可以这样写代码 11 | ![](http://upload-images.jianshu.io/upload_images/1429074-359b24305c5bd9f9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 12 | ###### 甚至这样写代码 13 | ![](http://upload-images.jianshu.io/upload_images/1429074-aca80267c055d8b1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 14 | 15 | # 如何使用 16 | 将XRCategory文件夹中的所有文件添加到项目中,导入主头文件XRCategory.h即可 17 | 18 | ### 命名规范 19 | 大部分命名与系统一样,所以使用起来非常方便,为了避免与系统的完全重名,采用以下方式用以区分 20 | 21 | ###### 1.名称过短无法缩写时,采用首字母大写的方式 22 | 比如view的frame,这里使用Frame,xx.Frame(CGRect),label的text,使用Text,imageView的image,使用Image 23 | 24 | ###### 2.名称过长时采用缩写的方式 25 | 比如scrollview设置是否显示垂直滚动条,系统的是showsVerticalScrollIndicator,这里用的是showVIndicator,基本上前面几个字母都与系统的一致,查找方便 26 | 27 | ###### 3.坐标尺寸相关方法的扩充 28 | 比如原方法 Frame(CGRect frame):直接传frame 29 | 30 | 扩充方法 frameEle(CGFloat x, CGFloat y, CGFloat width, CGFloat height)传递x、y、width、height。 31 | 32 | Ele是element的缩写,即元素的意思,类似的还有Bounds、boundsEle、Center、CenterEle、origin、originEle、size、sizeEle 33 | 34 | 也可以直接对单个元素赋值view.x(0).height(20).centerY(10) 35 | 36 | ###### 4.参数的顺序也与系统的一致 37 | 比如addTarget:action:forControlEvents:的参数依次为target、action、controlEvent,这里封装的方法参数顺序也是这样btn.addTarget(target、action、controlEvent) 38 | 39 | >总的来说,就跟使用系统的差不多,系统的叫啥,用的时候就直接敲啥,然后看自动提示,返回值类型为block的就是封装好的方法 40 | 41 | ### 关于点语法 42 | 并不是所有的方法都可以一直.下去,有两种情况是不能继续点的 43 | ###### 1.调用父类方法后不能继续.自己的方法 44 | 比如以下代码就是错误的 45 | ![](http://upload-images.jianshu.io/upload_images/1429074-fadda47e23a8351a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 46 | 47 | frameEle是其父类UIView的方法,所以frameEle()这个block的返回值是UIView,而UIView是没有setTitleForState这个方法的 48 | 49 | >子类方法后可以继续.父类方法,但是父类方法后不能继续.子类方法,当然父类方法后可以继续.父类方法 50 | 51 | ###### 2.block返回值不为方法调用者时不能继续. 52 | 比如以下代码就是错误的 53 | ![](http://upload-images.jianshu.io/upload_images/1429074-f2839393a804de67.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 54 | 55 | titleForState方法是用来获取按钮某个状态下的标题的,它的返回值类型是NSString,并不是按钮本身,所以不能继续. 56 | 57 | >一般用来赋值的都会返回调用者本身,可以继续点,用来取值的则返回你要取的值,不能继续往下点。上图的例子返回值是NSString,虽然不能继续点button的方法,但是可以继续点string的方法 58 | 59 | ### 注意事项 60 | ###### 1.代码有中文 61 | 如果代码中带有中文字符串,后面就会没有自动提示,点不出来,所以尽量将有中文的代码放在后面,类似这样 62 | ![](http://upload-images.jianshu.io/upload_images/1429074-494d1ff868506198.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 63 | 64 | ###### 2.不可变类 65 | NSString、NSArray、NSSDictionary这几个不可变类,其block的返回值大多不是它们本身,所以使用时尽量不要连着点。 66 | NSMutableString、NSMutableArray、NSMutableDictionary不存在这个问题 67 | 68 | ###### 3.提供了直接访问frame相关结构体成员的方法 69 | 鉴于很多开发者会在项目中创建一个分类,用来直接获取视图的坐标跟尺寸,比如view.x、view.width,这样一来就会与该分类中的属性重名,于是就直接提供了这样的属性,不过全部采用首字母大写的方式用以区分,比如view.X、view.Width、view.CenterY 70 | 71 | #### 赋值使用view.x(10)、view.width(100),取值使用view.X、view.Width 72 | >用了这个分类,就不需要额外再写分类来直接获取视图的坐标跟尺寸了 73 | 74 | # 结束语 75 | 由于精力有限,目前只针对以下类的常用属性及方法做了封装 76 | 77 | UIView、UIButton、UILabel 78 | 79 | UITextField、UITextView、UIImageView 80 | 81 | UIScrollView、UITableView 82 | 83 | NSString、NSArray、NSDictionary 84 | 85 | NSMutableString、NSMutableArray、NSMutableDictionary 86 | 87 | 以后会不定期的添加一些新的属性和方法以及一些其他的类 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /XRCategory.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "XRCategory" 4 | s.version = "1.0.1" 5 | s.summary = "a powerful category,make development easier" 6 | 7 | s.homepage = "https://github.com/codingZero/XRCategory" 8 | 9 | s.license = "MIT" 10 | 11 | s.author = { "codingZero" => "yd13150@vip.qq.com" } 12 | 13 | s.social_media_url = "http://www.jianshu.com/users/425e4eed60ca/latest_articles" 14 | 15 | s.platform = :ios, "7.0" 16 | 17 | s.source = { :git => "https://github.com/codingZero/XRCategory.git", :tag => s.version } 18 | 19 | 20 | s.source_files = "XRCategory/*.{h,m}" 21 | 22 | s.requires_arc = true 23 | 24 | end 25 | -------------------------------------------------------------------------------- /XRCategory/NSArray+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (XRCategory) 12 | + (instancetype)createWithArray:(NSArray *)array :(void(^)(NSArray *obj))block; 13 | 14 | @property (nonatomic, strong, readonly) NSArray *(^arrayByAddObject)(id); 15 | @property (nonatomic, strong, readonly) NSArray *(^arrayByAddObjFromArray)(NSArray *); 16 | @property (nonatomic, strong, readonly) NSString *(^componentsJoinByStr)(NSString *); 17 | @property (nonatomic, strong, readonly) BOOL (^containsObject)(id); 18 | @property (nonatomic, strong, readonly) NSUInteger (^indexOfObject)(id); 19 | @property (nonatomic, strong, readonly) NSUInteger (^indexOfObjInRange)(id, NSRange); 20 | @property (nonatomic, strong, readonly) BOOL (^isEqualToArray)(NSArray *); 21 | @property (nonatomic, strong, readonly) BOOL (^writeToFileAtomical)(NSString *, BOOL); 22 | @property (nonatomic, strong, readonly) BOOL (^writeToURLAtomical)(NSURL *, BOOL); 23 | 24 | /** 25 | * makeObjectsPerformSelector:(SEL)aSelector 26 | */ 27 | @property (nonatomic, strong, readonly) NSArray *(^makeObjPerformSel)(SEL); 28 | 29 | /** 30 | * makeObjectsPerformSelector:(SEL)aSelector withObject:(nullable id)argument 31 | */ 32 | @property (nonatomic, strong, readonly) NSArray *(^makeObjPerformSelWithObj)(SEL, id); 33 | 34 | @property (nonatomic, strong, readonly) id (^objectAtIndex)(NSUInteger); 35 | @property (nonatomic, strong, readonly) NSArray *(^objectsAtIndexes)(NSIndexSet *); 36 | 37 | @end 38 | 39 | 40 | @interface NSMutableArray (XRCategory) 41 | + (instancetype)create:(void(^)(NSMutableArray *obj))block; 42 | + (instancetype)createWithArray:(NSArray *)array :(void(^)(NSMutableArray *obj))block; 43 | @property (nonatomic, strong, readonly) NSMutableArray *(^addObject)(id); 44 | @property (nonatomic, strong, readonly) NSMutableArray *(^insertObjAtIndex)(id, NSUInteger); 45 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeLastObj)(); 46 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjAtIndex)(NSUInteger); 47 | @property (nonatomic, strong, readonly) NSMutableArray *(^reaplaceObjAtIndexWithObj)(NSUInteger ,id); 48 | @property (nonatomic, strong, readonly) NSMutableArray *(^addObjsFromArray)(NSArray *); 49 | @property (nonatomic, strong, readonly) NSMutableArray *(^exchangeObjAtIndexWithIndex)(NSUInteger, NSUInteger); 50 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeAllObjs)(); 51 | 52 | /** 53 | * removeObject:(ObjectType)anObject inRange:(NSRange)range 54 | */ 55 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjInRange)(id, NSRange); 56 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObject)(id); 57 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjsInArray)(NSArray *); 58 | /** 59 | * removeObjectsInRange:(NSRange)range 60 | */ 61 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjsInRange)(NSRange); 62 | 63 | /** 64 | * replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray range:(NSRange)otherRange 65 | */ 66 | @property (nonatomic, strong, readonly) NSMutableArray *(^replaceObjsInRangeWithObjsFromArrayRange)(NSRange, NSArray *, NSRange); 67 | 68 | /** 69 | * replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray 70 | */ 71 | @property (nonatomic, strong, readonly) NSMutableArray *(^replaceObjsInRangeWithObjsFromArray)(NSRange, NSArray *); 72 | 73 | @property (nonatomic, strong, readonly) NSMutableArray *(^setArray)(NSArray *); 74 | 75 | /** 76 | * insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes 77 | */ 78 | @property (nonatomic, strong, readonly) NSMutableArray *(^insertObjsAtIndexes)(NSArray *, NSIndexSet *); 79 | 80 | /** 81 | * removeObjectsAtIndexes:(NSIndexSet *)indexes 82 | */ 83 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjsAtIndexes)(NSIndexSet *); 84 | 85 | /** 86 | * replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects 87 | */ 88 | @property (nonatomic, strong, readonly) NSMutableArray *(^replaceObjsAtIndexesWithObjsFromArray)(NSIndexSet *, NSArray *); 89 | 90 | @property (nonatomic, strong, readonly) NSMutableArray *(^sortUsingComparator)(NSComparator); 91 | @end 92 | -------------------------------------------------------------------------------- /XRCategory/NSArray+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+XRCategory.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "NSArray+XRCategory.h" 10 | 11 | @implementation NSArray (XRCategory) 12 | 13 | + (instancetype)createWithArray:(NSArray *)array :(void (^)(NSArray *))block{ 14 | NSArray *obj = [[NSArray alloc] initWithArray:array]; 15 | if (block) block(obj); 16 | return obj; 17 | } 18 | 19 | 20 | - (NSArray *(^)(id))arrayByAddObject { 21 | return ^(id obj) { 22 | return [self arrayByAddingObject:obj]; 23 | }; 24 | } 25 | 26 | - (NSArray *(^)(NSArray *))arrayByAddObjFromArray { 27 | return ^(NSArray *otherArray) { 28 | return [self arrayByAddingObjectsFromArray:otherArray]; 29 | }; 30 | } 31 | 32 | - (NSString *(^)(NSString *))componentsJoinByStr { 33 | return ^(NSString *str) { 34 | return [self componentsJoinedByString:str]; 35 | }; 36 | } 37 | 38 | 39 | - (NSUInteger (^)(id))indexOfObject { 40 | return ^(id obj) { 41 | return [self indexOfObject:obj]; 42 | }; 43 | } 44 | 45 | - (NSUInteger (^)(id, NSRange))indexOfObjInRange { 46 | return ^(id obj, NSRange range){ 47 | return [self indexOfObject:obj inRange:range]; 48 | }; 49 | } 50 | 51 | - (BOOL (^)(id))containsObject { 52 | return ^(id obj) { 53 | return [self containsObject:obj]; 54 | }; 55 | } 56 | 57 | - (BOOL (^)(NSArray *))isEqualToArray { 58 | return ^(NSArray *otherArray) { 59 | return [self isEqualToArray:otherArray]; 60 | }; 61 | } 62 | 63 | 64 | - (BOOL (^)(NSString *, BOOL))writeToFileAtomical { 65 | return ^(NSString *path, BOOL b) { 66 | return [self writeToFile:path atomically:b]; 67 | }; 68 | } 69 | 70 | - (BOOL (^)(NSURL *, BOOL))writeToURLAtomical { 71 | return ^(NSURL *url, BOOL b) { 72 | return [self writeToURL:url atomically:b]; 73 | }; 74 | } 75 | 76 | - (NSArray *(^)(SEL))makeObjPerformSel { 77 | return ^(SEL selector) { 78 | [self makeObjectsPerformSelector:selector]; 79 | return self; 80 | }; 81 | } 82 | 83 | 84 | - (NSArray *(^)(SEL, id))makeObjPerformSelWithObj { 85 | return ^(SEL selector, id obj) { 86 | [self makeObjectsPerformSelector:selector withObject:obj]; 87 | return self; 88 | }; 89 | } 90 | 91 | - (id (^)(NSUInteger))objectAtIndex { 92 | return ^(NSUInteger index) { 93 | return [self objectAtIndex:index]; 94 | }; 95 | } 96 | 97 | - (NSArray *(^)(NSIndexSet *))objectsAtIndexes { 98 | return ^(NSIndexSet *set) { 99 | return [self objectsAtIndexes:set]; 100 | }; 101 | } 102 | @end 103 | 104 | 105 | 106 | @implementation NSMutableArray (XRCategory) 107 | 108 | + (instancetype)create:(void (^)(NSMutableArray *))block{ 109 | NSMutableArray *obj = [[NSMutableArray alloc] init]; 110 | if (block) block(obj); 111 | return obj; 112 | } 113 | 114 | + (instancetype)createWithArray:(NSArray *)array :(void (^)(NSMutableArray *))block{ 115 | NSMutableArray *obj = [[NSMutableArray alloc] initWithArray:array]; 116 | if (block) block(obj); 117 | return obj; 118 | } 119 | 120 | - (NSMutableArray *(^)(id))addObject { 121 | return ^(id obj) { 122 | [self addObject:obj]; 123 | return self; 124 | }; 125 | } 126 | 127 | - (NSMutableArray *(^)(id, NSUInteger))insertObjAtIndex { 128 | return ^(id obj, NSUInteger index) { 129 | [self insertObject:obj atIndex:index]; 130 | return self; 131 | }; 132 | } 133 | 134 | - (NSMutableArray *(^)())removeLastObj { 135 | return ^() { 136 | [self removeLastObject]; 137 | return self; 138 | }; 139 | } 140 | 141 | - (NSMutableArray *(^)(NSUInteger))removeObjAtIndex { 142 | return ^(NSUInteger index) { 143 | [self removeObjectAtIndex:index]; 144 | return self; 145 | }; 146 | } 147 | 148 | - (NSMutableArray *(^)(NSUInteger, id))reaplaceObjAtIndexWithObj { 149 | return ^(NSUInteger index, id obj) { 150 | [self replaceObjectAtIndex:index withObject:obj]; 151 | return self; 152 | }; 153 | } 154 | 155 | - (NSMutableArray *(^)(NSArray *))addObjsFromArray { 156 | return ^(NSArray *array) { 157 | [self addObjectsFromArray:array]; 158 | return self; 159 | }; 160 | } 161 | 162 | - (NSMutableArray *(^)(NSUInteger, NSUInteger))exchangeObjAtIndexWithIndex { 163 | return ^(NSUInteger index1, NSUInteger index2) { 164 | [self exchangeObjectAtIndex:index1 withObjectAtIndex:index2]; 165 | return self; 166 | }; 167 | } 168 | 169 | - (NSMutableArray *(^)())removeAllObjs{ 170 | return ^(){ 171 | [self removeAllObjects]; 172 | return self; 173 | }; 174 | } 175 | 176 | - (NSMutableArray *(^)(id, NSRange))removeObjInRange { 177 | return ^(id obj, NSRange range) { 178 | [self removeObject:obj inRange:range]; 179 | return self; 180 | }; 181 | } 182 | 183 | - (NSMutableArray *(^)(id))removeObject { 184 | return ^(id obj) { 185 | [self removeObject:obj]; 186 | return self; 187 | }; 188 | } 189 | 190 | - (NSMutableArray *(^)(NSArray *))removeObjsInArray { 191 | return ^(NSArray *array) { 192 | [self removeObjectsInArray:array]; 193 | return self; 194 | }; 195 | } 196 | 197 | - (NSMutableArray *(^)(NSRange))removeObjsInRange { 198 | return ^(NSRange range){ 199 | [self removeObjectsInRange:range]; 200 | return self; 201 | }; 202 | } 203 | 204 | 205 | - (NSMutableArray *(^)(NSRange, NSArray *, NSRange))replaceObjsInRangeWithObjsFromArrayRange { 206 | return ^(NSRange range, NSArray *otherArray, NSRange otherRange) { 207 | [self replaceObjectsInRange:range withObjectsFromArray:otherArray range:otherRange]; 208 | return self; 209 | }; 210 | } 211 | 212 | 213 | - (NSMutableArray *(^)(NSRange, NSArray *))replaceObjsInRangeWithObjsFromArray { 214 | return ^(NSRange range, NSArray *otherArray) { 215 | [self replaceObjectsInRange:range withObjectsFromArray:otherArray]; 216 | return self; 217 | }; 218 | } 219 | 220 | - (NSMutableArray *(^)(NSArray *))setArray { 221 | return ^(NSArray *array) { 222 | [self setArray:array]; 223 | return self; 224 | }; 225 | } 226 | 227 | - (NSMutableArray *(^)(NSArray *, NSIndexSet *))insertObjsAtIndexes { 228 | return ^(NSArray *array, NSIndexSet *set) { 229 | [self insertObjects:array atIndexes:set]; 230 | return self; 231 | }; 232 | } 233 | 234 | - (NSMutableArray *(^)(NSIndexSet *))removeObjsAtIndexes { 235 | return ^(NSIndexSet *set) { 236 | [self removeObjectsAtIndexes:set]; 237 | return self; 238 | }; 239 | } 240 | 241 | - (NSMutableArray *(^)(NSIndexSet *, NSArray *))replaceObjsAtIndexesWithObjsFromArray { 242 | return ^(NSIndexSet *set, NSArray *array){ 243 | [self replaceObjectsAtIndexes:set withObjects:array]; 244 | return self; 245 | }; 246 | } 247 | 248 | 249 | - (NSMutableArray *(^)(NSComparator))sortUsingComparator { 250 | return ^(NSComparator comparator) { 251 | [self sortedArrayUsingComparator:comparator]; 252 | return self; 253 | }; 254 | } 255 | 256 | @end 257 | -------------------------------------------------------------------------------- /XRCategory/NSDictionary+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDictionary (XRCategory) 12 | + (instancetype)createWithDicdionary:(NSDictionary *)dic :(void(^)(NSDictionary *obj))block; 13 | @property (nonatomic, strong, readonly) id (^objectForKey)(id); 14 | @property (nonatomic, strong, readonly) NSArray *(^allKeysForObject)(id); 15 | @property (nonatomic, strong, readonly) BOOL (^isEqualToDictionary)(NSDictionary *); 16 | /** 17 | * objectsForKeys:(NSArray *)keys notFoundMarker:(ObjectType)marker 18 | */ 19 | @property (nonatomic, strong, readonly) NSArray *(^objsForKeysNotFindMarker)(NSArray *, id); 20 | @property (nonatomic, strong, readonly) BOOL (^writeToFileAtomical)(NSString *, BOOL); 21 | @property (nonatomic, strong, readonly) BOOL (^writeToURLAtomical)(NSURL *,BOOL); 22 | 23 | /** 24 | * keysSortedByValueUsingSelector:(SEL)comparator 25 | */ 26 | @property (nonatomic, strong, readonly) NSArray *(^keysSortByValueUseSel)(SEL); 27 | @end 28 | 29 | @interface NSMutableDictionary (XRCategory) 30 | + (instancetype)create:(void(^)(NSMutableDictionary *obj))block; 31 | + (instancetype)createWithDicdionary:(NSDictionary *)dic :(void(^)(NSMutableDictionary *obj))block; 32 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^removeObjectForKey)(id); 33 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^setObjectForKey)(id, id); 34 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^removeAllObjs)(); 35 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^removeObjsForKeys)(NSArray *); 36 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^setDictionary)(NSDictionary *); 37 | @end -------------------------------------------------------------------------------- /XRCategory/NSDictionary+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+XRCategory.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+XRCategory.h" 10 | 11 | @implementation NSDictionary (XRCategory) 12 | 13 | + (instancetype)createWithDicdionary:(NSDictionary *)dic :(void (^)(NSDictionary *))block { 14 | NSDictionary *obj = [[NSDictionary alloc] initWithDictionary:dic]; 15 | if (block) block(obj); 16 | return obj; 17 | } 18 | 19 | - (id (^)(id))objectForKey { 20 | return ^(id key) { 21 | return [self objectForKey:key]; 22 | }; 23 | } 24 | 25 | - (NSArray *(^)(id))allKeysForObject { 26 | return ^(id obj) { 27 | return [self allKeysForObject:obj]; 28 | }; 29 | } 30 | 31 | - (BOOL (^)(NSDictionary *))isEqualToDictionary { 32 | return ^(NSDictionary *dic) { 33 | return [self isEqualToDictionary:dic]; 34 | }; 35 | } 36 | 37 | - (NSArray *(^)(NSArray *, id))objsForKeysNotFindMarker { 38 | return ^(NSArray *keys, id marker) { 39 | return [self objectsForKeys:keys notFoundMarker:marker]; 40 | }; 41 | } 42 | 43 | - (BOOL (^)(NSString *, BOOL))writeToFileAtomical { 44 | return ^(NSString *path, BOOL b) { 45 | return [self writeToFile:path atomically:b]; 46 | }; 47 | } 48 | 49 | - (BOOL (^)(NSURL *, BOOL))writeToURLAtomical { 50 | return ^(NSURL *url, BOOL b) { 51 | return [self writeToURL:url atomically:b]; 52 | }; 53 | } 54 | 55 | - (NSArray *(^)(SEL))keysSortByValueUseSel { 56 | return ^(SEL sel){ 57 | return [self keysSortedByValueUsingSelector:sel]; 58 | }; 59 | } 60 | 61 | @end 62 | 63 | 64 | @implementation NSMutableDictionary (XRCategory) 65 | + (instancetype)create:(void (^)(NSMutableDictionary *))block{ 66 | NSMutableDictionary *obj = [[NSMutableDictionary alloc] init]; 67 | if (block) block(obj); 68 | return obj; 69 | } 70 | 71 | + (instancetype)createWithDicdionary:(NSDictionary *)dic :(void (^)(NSMutableDictionary *))block { 72 | NSMutableDictionary *obj = [[NSMutableDictionary alloc] initWithDictionary:dic]; 73 | if (block) block(obj); 74 | return obj; 75 | } 76 | 77 | - (NSMutableDictionary *(^)(id))removeObjectForKey { 78 | return ^(id key) { 79 | [self removeObjectForKey:key]; 80 | return self; 81 | }; 82 | } 83 | 84 | - (NSMutableDictionary *(^)(id, id))setObjectForKey { 85 | return ^(id obj, id key) { 86 | [self setObject:obj forKey:key]; 87 | return self; 88 | }; 89 | } 90 | 91 | - (NSMutableDictionary *(^)())removeAllObjs { 92 | return ^(){ 93 | [self removeAllObjects]; 94 | return self; 95 | }; 96 | } 97 | 98 | - (NSMutableDictionary *(^)(NSArray *))removeObjsForKeys { 99 | return ^(NSArray *keys) { 100 | [self removeObjectsForKeys:keys]; 101 | return self; 102 | }; 103 | } 104 | 105 | - (NSMutableDictionary *(^)(NSDictionary *))setDictionary { 106 | return ^(NSDictionary *dic) { 107 | [self setDictionary:dic]; 108 | return self; 109 | }; 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /XRCategory/NSObject+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface NSObject (XRCategory) 11 | + (instancetype)create:(void(^)(id obj))block; 12 | 13 | 14 | //- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2; 15 | //@property (nonatomic, strong, readonly) id(^performSelWith2Obj)(SEL, id, id); 16 | 17 | //- (void)performSelector:(SEL)aSelector withObject:(nullable id)anArgument afterDelay:(NSTimeInterval)delay; 18 | @property (nonatomic, strong, readonly) void(^performSelAfterDelay)(SEL, id, NSTimeInterval); 19 | 20 | //- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(nullable id)arg waitUntilDone:(BOOL)wait; 21 | @property (nonatomic, strong, readonly) void(^performSelOnMainThread)(SEL, id, BOOL); 22 | 23 | //- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(nullable id)arg waitUntilDone:(BOOL)wait 24 | @property (nonatomic, strong, readonly) void(^performSelOnThread)(SEL, NSThread *, id, BOOL); 25 | 26 | //- (void)performSelectorInBackground:(SEL)aSelector withObject:(nullable id)arg 27 | @property (nonatomic, strong, readonly) void(^performSelInBackground)(SEL, id); 28 | 29 | //- (BOOL)isKindOfClass:(Class)aClass; 30 | @property (nonatomic, strong, readonly) BOOL(^isKindOfClass)(Class); 31 | 32 | //- (BOOL)isMemberOfClass:(Class)aClass; 33 | @property (nonatomic, strong, readonly) BOOL(^isMemberOfClass)(Class); 34 | 35 | //- (BOOL)conformsToProtocol:(Protocol *)aProtocol; 36 | @property (nonatomic, strong, readonly) BOOL(^conformsToProtocol)(Protocol *); 37 | 38 | //- (BOOL)respondsToSelector:(SEL)aSelector; 39 | @property (nonatomic, strong, readonly) BOOL(^respondsToSelector)(SEL); 40 | 41 | //- (BOOL)isEqual:(id)object; 42 | @property (nonatomic, strong, readonly) BOOL(^isEqual)(id); 43 | 44 | @property (nonatomic, strong, readonly) id (^valueForKey)(NSString *); 45 | @property (nonatomic, strong, readonly) void(^setValueForKey)(id, NSString *); 46 | @property (nonatomic, strong, readonly) id (^valueForKeyPath)(NSString *); 47 | @property (nonatomic, strong, readonly) void(^setValueForKeyPath)(id, NSString *); 48 | @property (nonatomic, strong, readonly) void(^setValuesForKeysWithDic)(NSDictionary *); 49 | @property (nonatomic, strong, readonly) NSDictionary *(^dicWithValuesForKeys)(NSArray *); 50 | 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /XRCategory/NSObject+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "NSObject+XRCategory.h" 9 | 10 | @implementation NSObject (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(id))block{ 13 | id obj = [[self alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | //- (id (^)(SEL, id, id))performSelWith2Obj { 19 | // return ^(SEL selector, id obj1, id obj2) { 20 | // return [self performSelector:selector withObject:obj1 withObject:obj2]; 21 | // }; 22 | //} 23 | 24 | 25 | - (void (^)(SEL, id, NSTimeInterval))performSelAfterDelay { 26 | return ^(SEL selector, id obj, NSTimeInterval delay){ 27 | [self performSelector:selector withObject:obj afterDelay:delay]; 28 | }; 29 | } 30 | 31 | 32 | - (void(^)(SEL, id, BOOL))performSelOnMainThread { 33 | return ^(SEL selector, id obj, BOOL b) { 34 | [self performSelectorOnMainThread:selector withObject:obj waitUntilDone:b]; 35 | }; 36 | } 37 | 38 | - (void(^)(SEL, NSThread *, id, BOOL))performSelOnThread { 39 | return ^(SEL selector, NSThread * thread, id obj, BOOL b) { 40 | return [self performSelector:selector onThread:thread withObject:obj waitUntilDone:b]; 41 | }; 42 | } 43 | 44 | - (void(^)(SEL , id))performSelInBackground { 45 | return ^(SEL selector, id obj) { 46 | return [self performSelectorInBackground:selector withObject:obj]; 47 | }; 48 | } 49 | 50 | 51 | - (BOOL (^)(__unsafe_unretained Class))isKindOfClass { 52 | return ^(Class class){ 53 | return [self isKindOfClass:class]; 54 | }; 55 | } 56 | 57 | - (BOOL (^)(__unsafe_unretained Class))isMemberOfClass { 58 | return ^(Class class){ 59 | return [self isMemberOfClass:class]; 60 | }; 61 | } 62 | 63 | - (BOOL (^)(Protocol *))conformsToProtocol { 64 | return ^(Protocol *protocol){ 65 | return [self conformsToProtocol:protocol]; 66 | }; 67 | } 68 | 69 | - (BOOL (^)(SEL))respondsToSelector { 70 | return ^(SEL selector){ 71 | return [self respondsToSelector:selector]; 72 | }; 73 | } 74 | 75 | - (BOOL (^)(id))isEqual { 76 | return ^(id obj){ 77 | return [self isKindOfClass:obj]; 78 | }; 79 | } 80 | 81 | - (id (^)(NSString *))valueForKey{ 82 | return ^(NSString *key) { 83 | return [self valueForKey:key]; 84 | }; 85 | } 86 | 87 | - (id (^)(NSString *))valueForKeyPath{ 88 | return ^(NSString *keyPath) { 89 | return [self valueForKeyPath:keyPath]; 90 | }; 91 | } 92 | 93 | - (void (^)(id, NSString *))setValueForKey { 94 | return ^(id value, NSString * key) { 95 | [self setValue:value forKey:key]; 96 | }; 97 | } 98 | 99 | - (void (^)(id, NSString *))setValueForKeyPath { 100 | return ^(id value, NSString * keyPath) { 101 | [self setValue:value forKey:keyPath]; 102 | }; 103 | } 104 | 105 | - (void (^)(NSDictionary *))setValuesForKeysWithDic { 106 | return ^(NSDictionary *dic) { 107 | [self setValuesForKeysWithDictionary:dic]; 108 | }; 109 | } 110 | 111 | - (NSDictionary *(^)(NSArray *))dicWithValuesForKeys { 112 | return ^(NSArray *keys) { 113 | return [self dictionaryWithValuesForKeys:keys]; 114 | }; 115 | } 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /XRCategory/NSString+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (XRCategory) 12 | 13 | + (instancetype)createWithString:(NSString *)str :(void(^)(NSString *obj))block; 14 | 15 | @property (nonatomic, strong, readonly) unichar (^charAtIndex)(NSUInteger); 16 | @property (nonatomic, strong, readonly) NSString *(^subStrFromIndex)(NSUInteger); 17 | @property (nonatomic, strong, readonly) NSString *(^subStrToIndex)(NSUInteger); 18 | @property (nonatomic, strong, readonly) NSString *(^subStrWithRange)(NSRange); 19 | @property (nonatomic, strong, readonly) BOOL (^isEqualToString)(NSString *); 20 | @property (nonatomic, strong, readonly) NSComparisonResult (^compare)(NSString *); 21 | @property (nonatomic, strong, readonly) NSRange (^rangeOfString)(NSString *); 22 | @property (nonatomic, strong, readonly) BOOL (^hasPrefix)(NSString *); 23 | @property (nonatomic, strong, readonly) BOOL (^hasSuffix)(NSString *); 24 | @property (nonatomic, strong, readonly) BOOL (^containsString)(NSString *); 25 | @property (nonatomic, strong, readonly) NSString *(^stringByAppendStr)(NSString *); 26 | @property (nonatomic, strong, readonly) NSData *(^dataUsingEncoding)(NSStringEncoding); 27 | @property (nonatomic, strong, readonly) const char *(^cStringUsingEncoding)(NSStringEncoding); 28 | 29 | 30 | /** 31 | * componentsSeparatedByString:(NSString *)separator 32 | */ 33 | @property (nonatomic, strong, readonly) NSArray *(^componentSeparatByStr)(NSString *); 34 | 35 | /** 36 | * stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement 37 | */ 38 | @property (nonatomic, strong, readonly) NSString *(^stringByReplaceStringWithStr)(NSString *, NSString *); 39 | 40 | /** 41 | * stringByReplacingCharactersInRange:(NSRange)range withString:(NSString *)replacement 42 | */ 43 | @property (nonatomic, strong, readonly) NSString *(^stringByReplaceCharInRangeWithStr)(NSRange, NSString *); 44 | 45 | 46 | /** 47 | * writeToURL:(NSURL *)url atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error 48 | */ 49 | @property (nonatomic, strong, readonly) BOOL (^writeToFileAtomical)(NSString *, BOOL, NSStringEncoding, NSError **); 50 | 51 | /** 52 | * writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error 53 | */ 54 | @property (nonatomic, strong, readonly) BOOL (^writeToURLAtomical)(NSURL *, BOOL, NSStringEncoding, NSError **); 55 | 56 | 57 | @end 58 | 59 | 60 | @interface NSMutableString (XRCategory) 61 | 62 | + (instancetype)create:(void(^)(NSMutableString *obj))block; 63 | + (instancetype)createWithString:(NSString *)str :(void(^)(NSMutableString *obj))block; 64 | 65 | @property (nonatomic, strong, readonly) NSMutableString *(^replaceCharInRange)(NSRange, NSString *); 66 | @property (nonatomic, strong, readonly) NSMutableString *(^insertStrAtIndex)(NSString *, NSUInteger); 67 | @property (nonatomic, strong, readonly) NSMutableString *(^deleteCharInRange)(NSRange); 68 | @property (nonatomic, strong, readonly) NSMutableString *(^appendStr)(NSString *); 69 | @property (nonatomic, strong, readonly) NSMutableString *(^setString)(NSString *); 70 | @end 71 | -------------------------------------------------------------------------------- /XRCategory/NSString+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+XRCategory.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "NSString+XRCategory.h" 10 | 11 | @implementation NSString (XRCategory) 12 | 13 | 14 | + (instancetype)createWithString:(NSString *)str :(void (^)(NSString *))block{ 15 | NSString *obj = [[NSString alloc] initWithString:str]; 16 | if (block) block(obj); 17 | return obj; 18 | } 19 | 20 | - (unichar (^)(NSUInteger))charAtIndex { 21 | return ^(NSUInteger index){ 22 | return [self characterAtIndex:index]; 23 | }; 24 | } 25 | 26 | - (NSString *(^)(NSUInteger))subStrFromIndex { 27 | return ^(NSUInteger index){ 28 | return [self substringFromIndex:index]; 29 | }; 30 | } 31 | 32 | - (NSString *(^)(NSUInteger))subStrToIndex { 33 | return ^(NSUInteger index){ 34 | return [self substringToIndex:index]; 35 | }; 36 | } 37 | 38 | - (NSString *(^)(NSRange))subStrWithRange { 39 | return ^(NSRange range){ 40 | return [self substringWithRange:range]; 41 | }; 42 | } 43 | 44 | - (BOOL (^)(NSString *))isEqualToString{ 45 | return ^(NSString *str){ 46 | return [self isEqualToString:str]; 47 | }; 48 | } 49 | 50 | - (NSComparisonResult (^)(NSString *))compare{ 51 | return ^(NSString *str){ 52 | return [self compare:str]; 53 | }; 54 | } 55 | 56 | - (NSRange (^)(NSString *))rangeOfString { 57 | return ^(NSString *str){ 58 | return [self rangeOfString:str]; 59 | }; 60 | } 61 | 62 | - (BOOL (^)(NSString *))hasPrefix{ 63 | return ^(NSString *str){ 64 | return [self hasPrefix:str]; 65 | }; 66 | } 67 | 68 | - (BOOL (^)(NSString *))hasSuffix{ 69 | return ^(NSString *str){ 70 | return [self hasSuffix:str]; 71 | }; 72 | } 73 | 74 | - (BOOL (^)(NSString *))containsString{ 75 | return ^(NSString *str){ 76 | return [self containsString:str]; 77 | }; 78 | } 79 | 80 | - (NSString *(^)(NSString *))stringByAppendStr { 81 | return ^(NSString *str){ 82 | return [self stringByAppendingString:str]; 83 | }; 84 | } 85 | 86 | - (NSData *(^)(NSStringEncoding))dataUsingEncoding { 87 | return ^(NSStringEncoding encoding) { 88 | return [self dataUsingEncoding:encoding]; 89 | }; 90 | } 91 | 92 | - (const char *(^)(NSStringEncoding))cStringUsingEncoding { 93 | return ^(NSStringEncoding encoding) { 94 | return [self cStringUsingEncoding:encoding]; 95 | }; 96 | } 97 | 98 | - (NSArray *(^)(NSString *))componentSeparatByStr { 99 | return ^(NSString *str) { 100 | return [self componentsSeparatedByString:str]; 101 | }; 102 | } 103 | 104 | - (NSString *(^)(NSString *, NSString *))stringByReplaceStringWithStr { 105 | return ^(NSString *target, NSString *replacement) { 106 | return [self stringByReplacingOccurrencesOfString:target withString:replacement]; 107 | }; 108 | } 109 | 110 | 111 | - (NSString *(^)(NSRange, NSString *))stringByReplaceCharInRangeWithStr { 112 | return ^(NSRange range, NSString *replacement) { 113 | return [self stringByReplacingCharactersInRange:range withString:replacement]; 114 | }; 115 | } 116 | 117 | 118 | - (BOOL (^)(NSString *, BOOL, NSStringEncoding, NSError **))writeToFileAtomical { 119 | return ^(NSString *path, BOOL b, NSStringEncoding encoding, NSError **error){ 120 | return [self writeToFile:path atomically:b encoding:encoding error:error]; 121 | }; 122 | } 123 | 124 | 125 | - (BOOL (^)(NSURL *, BOOL, NSStringEncoding, NSError **)) writeToURLAtomical{ 126 | return ^(NSURL *url, BOOL b, NSStringEncoding encoding, NSError **error){ 127 | return [self writeToURL:url atomically:b encoding:encoding error:error]; 128 | }; 129 | } 130 | 131 | @end 132 | 133 | 134 | @implementation NSMutableString (XRCategory) 135 | 136 | 137 | + (instancetype)create:(void (^)(NSMutableString *))block{ 138 | NSMutableString *obj = [[NSMutableString alloc] init]; 139 | if (block) block(obj); 140 | return obj; 141 | } 142 | 143 | +(instancetype)createWithString:(NSString *)str :(void (^)(NSMutableString *))block { 144 | NSMutableString *obj = [[NSMutableString alloc] initWithString:str]; 145 | if (block) block(obj); 146 | return obj; 147 | } 148 | 149 | - (NSMutableString *(^)(NSRange, NSString *))replaceCharInRange { 150 | return ^(NSRange range, NSString *str) { 151 | [self replaceCharactersInRange:range withString:str]; 152 | return self; 153 | }; 154 | } 155 | 156 | - (NSMutableString *(^)(NSString *, NSUInteger))insertStrAtIndex { 157 | return ^(NSString *str, NSUInteger index) { 158 | [self insertString:str atIndex:index]; 159 | return self; 160 | }; 161 | } 162 | 163 | - (NSMutableString *(^)(NSRange))deleteCharInRange { 164 | return ^(NSRange range) { 165 | [self deleteCharactersInRange:range]; 166 | return self; 167 | }; 168 | } 169 | 170 | - (NSMutableString *(^)(NSString *))appendStr { 171 | return ^(NSString *str) { 172 | [self appendString:str]; 173 | return self; 174 | }; 175 | } 176 | 177 | - (NSMutableString *(^)(NSString *))setString { 178 | return ^( NSString *str) { 179 | [self setString:str]; 180 | return self; 181 | }; 182 | } 183 | 184 | 185 | @end 186 | -------------------------------------------------------------------------------- /XRCategory/UIButton+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIButton (XRCategory) 11 | + (instancetype)create:(void(^)(UIButton *obj))block; 12 | 13 | //contentEdgeInsets 14 | @property (nonatomic, strong, readonly) UIButton *(^contentEdge)(UIEdgeInsets); 15 | @property (nonatomic, strong, readonly) UIButton *(^contentEdgeEle)(CGFloat, CGFloat, CGFloat, CGFloat); 16 | 17 | //imageEdgeInsets 18 | @property (nonatomic, strong, readonly) UIButton *(^imageEdge)(UIEdgeInsets); 19 | @property (nonatomic, strong, readonly) UIButton *(^imageEdgeEle)(CGFloat, CGFloat, CGFloat, CGFloat); 20 | 21 | //titleEdgeInsets 22 | @property (nonatomic, strong, readonly) UIButton *(^titleEdge)(UIEdgeInsets); 23 | @property (nonatomic, strong, readonly) UIButton *(^titleEdgeEle)(CGFloat, CGFloat, CGFloat, CGFloat); 24 | 25 | @property (nonatomic, strong, readonly) UIButton *(^adjustImgWhenHighlight)(BOOL); 26 | @property (nonatomic, strong, readonly) UIButton *(^adjustImgWhenDisable)(BOOL); 27 | @property (nonatomic, strong, readonly) UIButton *(^showTouchWhenHighlight)(BOOL); 28 | 29 | @property (nonatomic, strong, readonly) UIButton *(^setTitleForState)(NSString *, UIControlState); 30 | @property (nonatomic, strong, readonly) UIButton *(^setTitleColorForState)(UIColor *, UIControlState); 31 | @property (nonatomic, strong, readonly) UIButton *(^setShadowColorForState)(UIColor *, UIControlState); 32 | @property (nonatomic, strong, readonly) UIButton *(^setImageForState)(UIImage *, UIControlState); 33 | @property (nonatomic, strong, readonly) UIButton *(^setBgImageForState)(UIImage *, UIControlState); 34 | @property (nonatomic, strong, readonly) UIButton *(^setAttrituteTitleForState)(NSAttributedString *, UIControlState); 35 | 36 | 37 | /** 38 | * 以下属性是用来取值的,返回值不为方法调用者 39 | */ 40 | @property (nonatomic, strong, readonly) NSString *(^titleForState)(UIControlState); 41 | @property (nonatomic, strong, readonly) NSAttributedString *(^attributeTitleForState)(UIControlState); 42 | @property (nonatomic, strong, readonly) UIColor *(^titleColorForState)(UIControlState); 43 | @property (nonatomic, strong, readonly) UIColor *(^shadowColorForState)(UIControlState); 44 | @property (nonatomic, strong, readonly) UIImage *(^imageForState)(UIControlState); 45 | @property (nonatomic, strong, readonly) UIImage *(^bgImageForState)(UIControlState); 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /XRCategory/UIButton+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIButton+XRCategory.h" 9 | 10 | @implementation UIButton (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UIButton *))block{ 13 | UIButton *obj = [[UIButton alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | - (UIButton *(^)(UIEdgeInsets))contentEdge { 19 | return ^(UIEdgeInsets edge){ 20 | self.contentEdgeInsets = edge; 21 | return self; 22 | }; 23 | } 24 | 25 | - (UIButton *(^)(CGFloat, CGFloat, CGFloat, CGFloat))contentEdgeEle { 26 | return ^(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right){ 27 | self.contentEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right); 28 | return self; 29 | }; 30 | } 31 | 32 | - (UIButton *(^)(UIEdgeInsets))titleEdge { 33 | return ^(UIEdgeInsets edge){ 34 | self.titleEdgeInsets = edge; 35 | return self; 36 | }; 37 | } 38 | 39 | - (UIButton *(^)(CGFloat, CGFloat, CGFloat, CGFloat))titleEdgeEle { 40 | return ^(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right){ 41 | self.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right); 42 | return self; 43 | }; 44 | } 45 | 46 | - (UIButton *(^)(UIEdgeInsets))imageEdge { 47 | return ^(UIEdgeInsets edge){ 48 | self.imageEdgeInsets = edge; 49 | return self; 50 | }; 51 | } 52 | 53 | - (UIButton *(^)(CGFloat, CGFloat, CGFloat, CGFloat))imageEdgeEle { 54 | return ^(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right){ 55 | self.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right); 56 | return self; 57 | }; 58 | } 59 | 60 | - (UIButton *(^)(BOOL))adjustImgWhenHighlight { 61 | return ^(BOOL b) { 62 | self.adjustsImageWhenHighlighted = b; 63 | return self; 64 | }; 65 | } 66 | 67 | - (UIButton *(^)(BOOL))adjustImgWhenDisable { 68 | return ^(BOOL b) { 69 | self.adjustsImageWhenDisabled = b; 70 | return self; 71 | }; 72 | } 73 | 74 | - (UIButton *(^)(BOOL))showTouchWhenHighlight { 75 | return ^(BOOL b) { 76 | self.showsTouchWhenHighlighted = b; 77 | return self; 78 | }; 79 | } 80 | 81 | - (UIButton *(^)(NSString *, UIControlState))setTitleForState { 82 | return ^(NSString *title, UIControlState state) { 83 | [self setTitle:title forState:state]; 84 | return self; 85 | }; 86 | } 87 | 88 | - (UIButton *(^)(NSAttributedString *, UIControlState))setAttrituteTitleForState { 89 | return ^(NSAttributedString *title, UIControlState state) { 90 | [self setAttributedTitle:title forState:state]; 91 | return self; 92 | }; 93 | } 94 | 95 | - (UIButton *(^)(UIColor *, UIControlState))setTitleColorForState { 96 | return ^(UIColor *color, UIControlState state) { 97 | [self setTitleColor:color forState:state]; 98 | return self; 99 | }; 100 | } 101 | 102 | - (UIButton *(^)(UIColor *, UIControlState))setShadowColorForState { 103 | return ^(UIColor *color, UIControlState state) { 104 | [self setTitleShadowColor:color forState:state]; 105 | return self; 106 | }; 107 | } 108 | 109 | 110 | - (UIButton *(^)(UIImage *, UIControlState))setImageForState { 111 | return ^(UIImage *image, UIControlState state) { 112 | [self setImage:image forState:state]; 113 | return self; 114 | }; 115 | } 116 | 117 | - (UIButton *(^)(UIImage *, UIControlState))setBgImageForState { 118 | return ^(UIImage *image, UIControlState state) { 119 | [self setBackgroundImage:image forState:state]; 120 | return self; 121 | }; 122 | } 123 | 124 | - (NSString *(^)(UIControlState))titleForState { 125 | return ^(UIControlState state){ 126 | return [self titleForState:state]; 127 | }; 128 | } 129 | 130 | - (NSAttributedString *(^)(UIControlState))attributeTitleForState { 131 | return ^(UIControlState state){ 132 | return [self attributedTitleForState:state]; 133 | }; 134 | } 135 | 136 | - (UIColor *(^)(UIControlState))titleColorForState { 137 | return ^(UIControlState state){ 138 | return [self titleColorForState:state]; 139 | }; 140 | } 141 | 142 | - (UIColor *(^)(UIControlState))shadowColorForState { 143 | return ^(UIControlState state){ 144 | return [self titleShadowColorForState:state]; 145 | }; 146 | } 147 | 148 | - (UIImage *(^)(UIControlState))imageForState { 149 | return ^(UIControlState state){ 150 | return [self imageForState:state]; 151 | }; 152 | } 153 | 154 | - (UIImage *(^)(UIControlState))bgImageForState { 155 | return ^(UIControlState state){ 156 | return [self backgroundImageForState:state]; 157 | }; 158 | } 159 | 160 | 161 | @end 162 | -------------------------------------------------------------------------------- /XRCategory/UIControl+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIControl+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIControl (XRCategory) 11 | //enabled 12 | @property (nonatomic, strong, readonly) UIControl *(^enable)(BOOL); 13 | 14 | //selected 15 | @property (nonatomic, strong, readonly) UIControl *(^select)(BOOL); 16 | 17 | //highlighted 18 | @property (nonatomic, strong, readonly) UIControl *(^highlight)(BOOL); 19 | 20 | //contentVerticalAlignment 21 | @property (nonatomic, strong, readonly) UIControl *(^verticalAlignment)(UIControlContentVerticalAlignment); 22 | 23 | //contentHorizontalAlignment 24 | @property (nonatomic, strong, readonly) UIControl *(^horizontalAlignment)(UIControlContentHorizontalAlignment); 25 | 26 | @property (nonatomic, strong, readonly) UIControl *(^addTarget)(id, SEL, UIControlEvents); 27 | @property (nonatomic, strong, readonly) UIControl *(^removeTarget)(id, SEL, UIControlEvents); 28 | @end 29 | -------------------------------------------------------------------------------- /XRCategory/UIControl+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIControl+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIControl+XRCategory.h" 9 | 10 | @implementation UIControl (XRCategory) 11 | 12 | - (UIControl *(^)(BOOL))enable { 13 | return ^(BOOL b){ 14 | self.enabled = b; 15 | return self; 16 | }; 17 | } 18 | 19 | - (UIControl *(^)(BOOL))select { 20 | return ^(BOOL b){ 21 | self.selected = b; 22 | return self; 23 | }; 24 | } 25 | 26 | - (UIControl *(^)(BOOL))highlight { 27 | return ^(BOOL b){ 28 | self.highlighted = b; 29 | return self; 30 | }; 31 | } 32 | 33 | - (UIControl *(^)(UIControlContentVerticalAlignment))verticalAlignment { 34 | return ^(UIControlContentVerticalAlignment alignment){ 35 | self.contentVerticalAlignment = alignment; 36 | return self; 37 | }; 38 | } 39 | 40 | - (UIControl *(^)(UIControlContentHorizontalAlignment))horizontalAlignment { 41 | return ^(UIControlContentHorizontalAlignment alignment){ 42 | self.contentHorizontalAlignment = alignment; 43 | return self; 44 | }; 45 | } 46 | 47 | - (UIControl *(^)(id, SEL, UIControlEvents))addTarget { 48 | return ^(id target, SEL action, UIControlEvents event){ 49 | [self addTarget:target action:action forControlEvents:event]; 50 | return self; 51 | }; 52 | } 53 | 54 | - (UIControl *(^)(id, SEL, UIControlEvents))removeTarget { 55 | return ^(id target, SEL action, UIControlEvents event){ 56 | [self removeTarget:target action:action forControlEvents:event]; 57 | return self; 58 | }; 59 | } 60 | @end 61 | -------------------------------------------------------------------------------- /XRCategory/UIImageView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIImageView (XRCategory) 11 | 12 | + (instancetype)create:(void(^)(UIImageView *obj))block; 13 | 14 | 15 | //image 16 | @property (nonatomic, strong, readonly) UIImageView *(^Image)(UIImage *); 17 | //highlightedImage 18 | @property (nonatomic, strong, readonly) UIImageView *(^highlightImg)(UIImage *); 19 | 20 | @property (nonatomic, strong, readonly) UIImageView *(^highlight)(BOOL); 21 | 22 | //animationImages 23 | @property (nonatomic, strong, readonly) UIImageView *(^animationImgs)(NSArray *); 24 | @property (nonatomic, strong, readonly) UIImageView *(^highlightAnimaImgs)(NSArray *); 25 | 26 | //animationDuration 27 | @property (nonatomic, strong, readonly) UIImageView *(^animaDuration)(NSTimeInterval); 28 | //animationRepeatCount 29 | @property (nonatomic, strong, readonly) UIImageView *(^animaRepeatCount)(NSInteger); 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /XRCategory/UIImageView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+XRCategory.m 3 | 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIImageView+XRCategory.h" 9 | 10 | @implementation UIImageView (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UIImageView *))block{ 13 | UIImageView *obj = [[UIImageView alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | - (UIImageView *(^)(UIImage *))Image { 19 | return ^(UIImage *image){ 20 | self.image = image; 21 | return self; 22 | }; 23 | } 24 | 25 | - (UIImageView *(^)(UIImage *))highlightImg { 26 | return ^(UIImage *image){ 27 | self.highlightedImage = image; 28 | return self; 29 | }; 30 | } 31 | 32 | - (UIImageView *(^)(BOOL))highlight { 33 | return ^(BOOL b){ 34 | self.highlighted = b; 35 | return self; 36 | }; 37 | } 38 | 39 | - (UIImageView *(^)(NSArray *))animationImgs { 40 | return ^(NSArray *images){ 41 | self.animationImages = images; 42 | return self; 43 | }; 44 | } 45 | 46 | - (UIImageView *(^)(NSArray *))highlightAnimaImgs { 47 | return ^(NSArray *images){ 48 | self.highlightedAnimationImages = images; 49 | return self; 50 | }; 51 | } 52 | 53 | - (UIImageView *(^)(NSTimeInterval))animaDuration { 54 | return ^(NSTimeInterval time){ 55 | self.animationDuration = time; 56 | return self; 57 | }; 58 | } 59 | 60 | - (UIImageView *(^)(NSInteger))animaRepeatCount { 61 | return ^(NSInteger count){ 62 | self.animationRepeatCount = count; 63 | return self; 64 | }; 65 | } 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /XRCategory/UILabel+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UILabel (XRCategory) 11 | + (instancetype)create:(void(^)(UILabel *obj))block; 12 | 13 | //text 14 | @property (nonatomic, strong, readonly) UILabel *(^Text)(NSString *); 15 | 16 | @property (nonatomic, strong, readonly) UILabel *(^attributeText)(NSAttributedString *); 17 | @property (nonatomic, strong, readonly) UILabel *(^TextAlignment)(NSTextAlignment); 18 | @property (nonatomic, strong, readonly) UILabel *(^TextColor)(UIColor *); 19 | @property (nonatomic, strong, readonly) UILabel *(^textColorRGB)(CGFloat, CGFloat, CGFloat, CGFloat); 20 | @property (nonatomic, strong, readonly) UILabel *(^highlightTextColor)(UIColor *); 21 | @property (nonatomic, strong, readonly) UILabel *(^highlight)(BOOL); 22 | @property (nonatomic, strong, readonly) UILabel *(^enable)(BOOL); 23 | 24 | //font 25 | @property (nonatomic, strong, readonly) UILabel *(^Font)(UIFont *); 26 | @property (nonatomic, strong, readonly) UILabel *(^fontSize)(NSInteger); 27 | @property (nonatomic, strong, readonly) UILabel *(^ShadowColor)(UIColor *); 28 | @property (nonatomic, strong, readonly) UILabel *(^ShadowOffset)(CGSize); 29 | @property (nonatomic, strong, readonly) UILabel *(^LineBreakMode)(NSLineBreakMode); 30 | @property (nonatomic, strong, readonly) UILabel *(^numberOfLine)(NSInteger); 31 | 32 | @property (nonatomic, strong, readonly) UILabel *(^adjustFontToFit)(BOOL); 33 | @property (nonatomic, strong, readonly) UILabel *(^baselineAdjust)(UIBaselineAdjustment); 34 | 35 | //drawTextInRect 36 | @property (nonatomic, strong, readonly) UILabel *(^drawText)(CGRect); 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /XRCategory/UILabel+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UILabel+XRCategory.h" 9 | 10 | @implementation UILabel (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UILabel *))block{ 13 | UILabel *obj = [[UILabel alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | - (UILabel *(^)(NSString *))Text { 19 | return ^(NSString *text){ 20 | self.text = text; 21 | return self; 22 | }; 23 | } 24 | 25 | - (UILabel *(^)(NSAttributedString *))attributeText { 26 | return ^(NSAttributedString *attributedText){ 27 | self.attributedText = attributedText; 28 | return self; 29 | }; 30 | } 31 | 32 | - (UILabel *(^)(NSTextAlignment))TextAlignment { 33 | return ^(NSTextAlignment alignment){ 34 | self.textAlignment = alignment; 35 | return self; 36 | }; 37 | } 38 | 39 | - (UILabel *(^)(UIColor *))TextColor { 40 | return ^(UIColor *color){ 41 | self.textColor = color; 42 | return self; 43 | }; 44 | } 45 | 46 | - (UILabel *(^)(CGFloat, CGFloat, CGFloat, CGFloat))textColorRGB { 47 | return ^(CGFloat r, CGFloat g, CGFloat b, CGFloat a){ 48 | self.textColor = [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:g / 255.0 alpha:a]; 49 | return self; 50 | }; 51 | } 52 | 53 | - (UILabel *(^)(UIColor *))highlightTextColor { 54 | return ^(UIColor *color){ 55 | self.highlightedTextColor = color; 56 | return self; 57 | }; 58 | } 59 | 60 | - (UILabel *(^)(BOOL))highlight { 61 | return ^(BOOL b){ 62 | self.highlighted = b; 63 | return self; 64 | }; 65 | } 66 | 67 | - (UILabel *(^)(BOOL))enable { 68 | return ^(BOOL b){ 69 | self.enabled = b; 70 | return self; 71 | }; 72 | } 73 | 74 | - (UILabel *(^)(UIFont *))Font { 75 | return ^(UIFont *font){ 76 | self.font = font; 77 | return self; 78 | }; 79 | } 80 | 81 | - (UILabel *(^)(NSInteger))fontSize { 82 | return ^(NSInteger size){ 83 | self.font = [UIFont systemFontOfSize:size]; 84 | return self; 85 | }; 86 | } 87 | 88 | - (UILabel *(^)(UIColor *))ShadowColor { 89 | return ^(UIColor *color){ 90 | self.shadowColor = color; 91 | return self; 92 | }; 93 | } 94 | 95 | - (UILabel *(^)(CGSize))ShadowOffset { 96 | return ^(CGSize size){ 97 | self.shadowOffset = size; 98 | return self; 99 | }; 100 | } 101 | 102 | - (UILabel *(^)(NSLineBreakMode))LineBreakMode { 103 | return ^(NSLineBreakMode mode){ 104 | self.lineBreakMode = mode; 105 | return self; 106 | }; 107 | } 108 | 109 | - (UILabel *(^)(NSInteger))numberOfLine { 110 | return ^(NSInteger num){ 111 | self.numberOfLines = num; 112 | return self; 113 | }; 114 | } 115 | 116 | - (UILabel *(^)(BOOL))adjustFontToFit { 117 | return ^(BOOL b){ 118 | self.adjustsFontSizeToFitWidth = b; 119 | return self; 120 | }; 121 | } 122 | 123 | - (UILabel *(^)(UIBaselineAdjustment))baselineAdjust { 124 | return ^(UIBaselineAdjustment adjustment){ 125 | self.baselineAdjustment = adjustment; 126 | return self; 127 | }; 128 | } 129 | 130 | - (UILabel *(^)(CGRect))drawText{ 131 | return ^(CGRect rect){ 132 | [self drawTextInRect:rect]; 133 | return self; 134 | }; 135 | } 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /XRCategory/UIScrollView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIScrollView (XRCategory) 11 | + (instancetype)create:(void(^)(UIScrollView *obj))block; 12 | 13 | 14 | @property (nonatomic, strong, readonly) UIScrollView *(^ContentOffset)(CGPoint); 15 | @property (nonatomic, strong, readonly) UIScrollView *(^ContentSize)(CGSize); 16 | @property (nonatomic, strong, readonly) UIScrollView *(^ContentInset)(UIEdgeInsets); 17 | @property (nonatomic, strong, readonly) UIScrollView *(^Delegate)(id); 18 | @property (nonatomic, strong, readonly) UIScrollView *(^bounce)(BOOL); 19 | 20 | //alwaysBounceVertical 21 | @property (nonatomic, strong, readonly) UIScrollView *(^alwaysBounceV)(BOOL); 22 | //alwaysBounceHorizontal 23 | @property (nonatomic, strong, readonly) UIScrollView *(^alwaysBounceH)(BOOL); 24 | @property (nonatomic, strong, readonly) UIScrollView *(^pagingEnable)(BOOL); 25 | @property (nonatomic, strong, readonly) UIScrollView *(^scrollEnable)(BOOL); 26 | 27 | //showsHorizontalScrollIndicator 28 | @property (nonatomic, strong, readonly) UIScrollView *(^showHIndicator)(BOOL); 29 | //showsVerticalScrollIndicator 30 | @property (nonatomic, strong, readonly) UIScrollView *(^showVIndicator)(BOOL); 31 | 32 | 33 | @property (nonatomic, strong, readonly) UIScrollView *(^scrollIndecatorInset)(UIEdgeInsets); 34 | @property (nonatomic, strong, readonly) UIScrollView *(^IndicatorStyle)(UIScrollViewIndicatorStyle); 35 | @property (nonatomic, strong, readonly) UIScrollView *(^deceleratRate)(CGFloat); 36 | @property (nonatomic, strong, readonly) UIScrollView *(^ZoomScale)(CGFloat); 37 | @property (nonatomic, strong, readonly) UIScrollView *(^minZoomScale)(CGFloat); 38 | @property (nonatomic, strong, readonly) UIScrollView *(^maxZoomScale)(CGFloat); 39 | @property (nonatomic, strong, readonly) UIScrollView *(^bounceZoom)(BOOL); 40 | @property (nonatomic, strong, readonly) UIScrollView *(^scrollToTop)(BOOL); 41 | 42 | 43 | 44 | //- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; 45 | @property (nonatomic, strong, readonly) UIScrollView *(^setContentOffsetAnimated)(CGPoint, BOOL); 46 | 47 | //- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated; 48 | @property (nonatomic, strong, readonly) UIScrollView *(^scrollRectToVisibleAnimated)(CGRect, BOOL); 49 | 50 | //- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated 51 | @property (nonatomic, strong, readonly) UIScrollView *(^setZoomScaleAnimated)(CGFloat, BOOL); 52 | 53 | //- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated 54 | @property (nonatomic, strong, readonly) UIScrollView *(^zoomToRectAnimated)(CGRect, BOOL); 55 | @end 56 | -------------------------------------------------------------------------------- /XRCategory/UIScrollView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIScrollView+XRCategory.h" 9 | 10 | @implementation UIScrollView (XRCategory) 11 | 12 | 13 | + (instancetype)create:(void (^)(UIScrollView *))block{ 14 | UIScrollView *obj = [[UIScrollView alloc] init]; 15 | if (block) block(obj); 16 | return obj; 17 | } 18 | 19 | - (UIScrollView *(^)(CGPoint))ContentOffset { 20 | return ^(CGPoint offset){ 21 | self.contentOffset = offset; 22 | return self; 23 | }; 24 | } 25 | 26 | - (UIScrollView *(^)(CGSize))ContentSize { 27 | return ^(CGSize size){ 28 | self.contentSize = size; 29 | return self; 30 | }; 31 | } 32 | 33 | - (UIScrollView *(^)(UIEdgeInsets))ContentInset { 34 | return ^(UIEdgeInsets edge){ 35 | self.contentInset = edge; 36 | return self; 37 | }; 38 | } 39 | 40 | - (UIScrollView *(^)(id))Delegate { 41 | return ^(id obj) { 42 | self.delegate = obj; 43 | return self; 44 | }; 45 | } 46 | 47 | - (UIScrollView *(^)(BOOL))bounce { 48 | return ^(BOOL b) { 49 | self.bounces = b; 50 | return self; 51 | }; 52 | } 53 | 54 | - (UIScrollView *(^)(BOOL))alwaysBounceV { 55 | return ^(BOOL b) { 56 | self.alwaysBounceVertical = b; 57 | return self; 58 | }; 59 | } 60 | 61 | - (UIScrollView *(^)(BOOL))alwaysBounceH { 62 | return ^(BOOL b) { 63 | self.alwaysBounceHorizontal = b; 64 | return self; 65 | }; 66 | } 67 | 68 | - (UIScrollView *(^)(BOOL))pagingEnable { 69 | return ^(BOOL b) { 70 | self.pagingEnabled = b; 71 | return self; 72 | }; 73 | } 74 | 75 | - (UIScrollView *(^)(BOOL))scrollEnable { 76 | return ^(BOOL b) { 77 | self.scrollEnabled = b; 78 | return self; 79 | }; 80 | } 81 | 82 | - (UIScrollView *(^)(BOOL))scrollToTop { 83 | return ^(BOOL b) { 84 | self.scrollsToTop = b; 85 | return self; 86 | }; 87 | } 88 | 89 | - (UIScrollView *(^)(BOOL))showHIndicator { 90 | return ^(BOOL b) { 91 | self.showsHorizontalScrollIndicator = b; 92 | return self; 93 | }; 94 | } 95 | 96 | - (UIScrollView *(^)(BOOL))showVIndicator { 97 | return ^(BOOL b) { 98 | self.showsVerticalScrollIndicator = b; 99 | return self; 100 | }; 101 | } 102 | 103 | - (UIScrollView *(^)(UIEdgeInsets))scrollIndecatorInset { 104 | return ^(UIEdgeInsets inset) { 105 | self.scrollIndicatorInsets = inset; 106 | return self; 107 | }; 108 | } 109 | 110 | - (UIScrollView *(^)(UIScrollViewIndicatorStyle))IndicatorStyle { 111 | return ^(UIScrollViewIndicatorStyle style) { 112 | self.indicatorStyle = style; 113 | return self; 114 | }; 115 | } 116 | 117 | - (UIScrollView *(^)(CGFloat))deceleratRate { 118 | return ^(CGFloat rate) { 119 | self.decelerationRate = rate; 120 | return self; 121 | }; 122 | } 123 | 124 | - (UIScrollView *(^)(CGFloat))ZoomScale { 125 | return ^(CGFloat scale) { 126 | self.zoomScale = scale; 127 | return self; 128 | }; 129 | } 130 | 131 | - (UIScrollView *(^)(CGFloat))minZoomScale { 132 | return ^(CGFloat scale) { 133 | self.minimumZoomScale = scale; 134 | return self; 135 | }; 136 | } 137 | 138 | - (UIScrollView *(^)(CGFloat))maxZoomScale { 139 | return ^(CGFloat scale) { 140 | self.maximumZoomScale = scale; 141 | return self; 142 | }; 143 | } 144 | 145 | - (UIScrollView *(^)(BOOL))bounceZoom { 146 | return ^(BOOL b) { 147 | self.bouncesZoom = b; 148 | return self; 149 | }; 150 | } 151 | 152 | 153 | - (UIScrollView *(^)(CGPoint, BOOL))setContentOffsetAnimated { 154 | return ^(CGPoint offset, BOOL b) { 155 | [self setContentOffset:offset animated:b]; 156 | return self; 157 | }; 158 | } 159 | 160 | - (UIScrollView *(^)(CGRect, BOOL))scrollRectToVisibleAnimated { 161 | return ^(CGRect rect, BOOL b) { 162 | [self scrollRectToVisible:rect animated:b]; 163 | return self; 164 | }; 165 | } 166 | 167 | - (UIScrollView *(^)(CGFloat, BOOL))setZoomScaleAnimated { 168 | return ^(CGFloat scale, BOOL b) { 169 | [self setZoomScale:scale animated:b]; 170 | return self; 171 | }; 172 | } 173 | 174 | - (UIScrollView *(^)(CGRect, BOOL))zoomToRectAnimated { 175 | return ^(CGRect rect, BOOL b) { 176 | [self zoomToRect:rect animated:b]; 177 | return self; 178 | }; 179 | } 180 | 181 | @end 182 | -------------------------------------------------------------------------------- /XRCategory/UITableView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITableView (XRCategory) 12 | + (instancetype)create:(void(^)(UITableView *obj))block; 13 | + (instancetype)createWithStyle:(UITableViewStyle)style :(void(^)(UITableView *obj))block; 14 | @property (nonatomic, strong, readonly) UITableView *(^DataSource)(id); 15 | @property (nonatomic, strong, readonly) UITableView *(^Delegate)(id); 16 | @property (nonatomic, strong, readonly) UITableView *(^RowHeight)(CGFloat); 17 | @property (nonatomic, strong, readonly) UITableView *(^sectionHeadHeight)(CGFloat); 18 | @property (nonatomic, strong, readonly) UITableView *(^sectionFootHeight)(CGFloat); 19 | @property (nonatomic, strong, readonly) UITableView *(^estimateRowHeight)(CGFloat); 20 | @property (nonatomic, strong, readonly) UITableView *(^separatInset)(UIEdgeInsets); 21 | @property (nonatomic, strong, readonly) UITableView *(^bgView)(UIView *); 22 | @property (nonatomic, strong, readonly) UITableView *(^edit)(BOOL); 23 | @property (nonatomic, strong, readonly) UITableView *(^allowSelect)(BOOL); 24 | @property (nonatomic, strong, readonly) UITableView *(^allowMultSelect)(BOOL); 25 | @property (nonatomic, strong, readonly) UITableView *(^allowSelectDuringEdit)(BOOL); 26 | @property (nonatomic, strong, readonly) UITableView *(^allowMultSelectDuringEdit)(BOOL); 27 | @property (nonatomic, strong, readonly) UITableView *(^SectionIndexColor)(UIColor *); 28 | @property (nonatomic, strong, readonly) UITableView *(^sectionIndexBgColor)(UIColor *); 29 | @property (nonatomic, strong, readonly) UITableView *(^sectionIndexTrackBgColor)(UIColor *); 30 | @property (nonatomic, strong, readonly) UITableView *(^separatStyle)(UITableViewCellSeparatorStyle); 31 | @property (nonatomic, strong, readonly) UITableView *(^separatColor)(UIColor *); 32 | 33 | 34 | 35 | 36 | /** 37 | * scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated 38 | */ 39 | @property (nonatomic, strong, readonly) UITableView *(^scrollToIndexPathAtPositionAnimated)(NSIndexPath *, UITableViewScrollPosition, BOOL); 40 | 41 | /** 42 | * reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation 43 | */ 44 | @property (nonatomic, strong, readonly) UITableView *(^reloadSectionsWithAnimation)(NSIndexSet *, UITableViewRowAnimation); 45 | 46 | /** 47 | * reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 48 | */ 49 | @property (nonatomic, strong, readonly) UITableView *(^reloadRowsAtIndexPathsWithAnimation)(NSArray *, UITableViewRowAnimation); 50 | 51 | /** 52 | * moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath 53 | */ 54 | @property (nonatomic, strong, readonly) UITableView *(^moveRowAtIndexPathToIndexPath)(NSIndexPath *, NSIndexPath *); 55 | 56 | /** 57 | * selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition 58 | */ 59 | @property (nonatomic, strong, readonly) UITableView *(^selecRowAtIndexPathAnimatedScrollPosition)(NSIndexPath *, BOOL, UITableViewScrollPosition); 60 | 61 | /** 62 | * deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated 63 | */ 64 | @property (nonatomic, strong, readonly) UITableView *(^deselecRowAtIndexPathAnimated)(NSIndexPath *, BOOL); 65 | 66 | /** 67 | * setEditing:(BOOL)editing animated:(BOOL)animated 68 | */ 69 | @property (nonatomic, strong, readonly) UITableView *(^setEditingAnimated)(BOOL, BOOL); 70 | 71 | /** 72 | * registerNib:(nullable UINib *)nib forCellReuseIdentifier:(NSString *)identifier 73 | */ 74 | @property (nonatomic, strong, readonly) UITableView *(^registNibForCellId)(UINib *, NSString *); 75 | 76 | /** 77 | * registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier 78 | */ 79 | @property (nonatomic, strong, readonly) UITableView *(^registClassForCellId)(Class, NSString *); 80 | 81 | /** 82 | * registerNib:(nullable UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier 83 | */ 84 | @property (nonatomic, strong, readonly) UITableView *(^registNibForHeadFootViewId)(UINib *, NSString *); 85 | 86 | /** 87 | * registerClass:(nullable UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier 88 | */ 89 | @property (nonatomic, strong, readonly) UITableView *(^registClassForHeadFootViewId)(Class, NSString *); 90 | 91 | 92 | /** 93 | * numberOfRowsInSection:(NSInteger)section 94 | */ 95 | @property (nonatomic, strong, readonly) NSInteger(^numOfRowsInSection)(NSInteger); 96 | 97 | 98 | /** 99 | * indexPathForRowAtPoint:(CGPoint)point 100 | */ 101 | @property (nonatomic, strong, readonly) NSIndexPath *(^indexPathForRowAtPoint)(CGPoint); 102 | 103 | 104 | /** 105 | * indexPathForCell:(UITableViewCell *)cell 106 | */ 107 | @property (nonatomic, strong, readonly) NSIndexPath *(^indexPathForCell)(UITableViewCell *); 108 | 109 | /** 110 | * indexPathsForRowsInRect:(CGRect)rect 111 | */ 112 | @property (nonatomic, strong, readonly) NSArray *(^indexPathsForRowsInRect)(CGRect); 113 | 114 | 115 | /** 116 | * cellForRowAtIndexPath:(NSIndexPath *)indexPath 117 | */ 118 | @property (nonatomic, strong, readonly) UITableViewCell *(^cellForRowAtIndexPath)(NSIndexPath *); 119 | 120 | /** 121 | * headerViewForSection:(NSInteger)section 122 | */ 123 | @property (nonatomic, strong, readonly) UITableViewHeaderFooterView *(^headViewForSection)(NSInteger); 124 | 125 | /** 126 | * footerViewForSection:(NSInteger)section 127 | */ 128 | @property (nonatomic, strong, readonly) UITableViewHeaderFooterView *(^footViewForSection)(NSInteger); 129 | 130 | /** 131 | * dequeueReusableCellWithIdentifier:(NSString *)identifier 132 | */ 133 | @property (nonatomic, strong, readonly) UITableViewCell *(^dequeueReuseCellWithId)(NSString *); 134 | 135 | /** 136 | * dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath 137 | */ 138 | @property (nonatomic, strong, readonly) UITableViewCell *(^dequeueReuseCellWithIdForIndexPath)(NSString *, NSIndexPath *); 139 | 140 | /** 141 | * dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier 142 | */ 143 | @property (nonatomic, strong, readonly) UITableViewHeaderFooterView *(^dequeueReuseHeadFootViewWithId)(NSString *); 144 | 145 | @end 146 | -------------------------------------------------------------------------------- /XRCategory/UITableView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+XRCategory.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "UITableView+XRCategory.h" 10 | 11 | @implementation UITableView (XRCategory) 12 | 13 | 14 | 15 | + (instancetype)create:(void (^)(UITableView *))block{ 16 | UITableView *obj = [[UITableView alloc] init]; 17 | if (block) block(obj); 18 | return obj; 19 | } 20 | 21 | 22 | + (instancetype)createWithStyle:(UITableViewStyle)style :(void(^)(UITableView *obj))block { 23 | UITableView *obj = [[UITableView alloc] initWithFrame:CGRectZero style:style]; 24 | if (block) block(obj); 25 | return obj; 26 | } 27 | 28 | 29 | - (UITableView *(^)(id))DataSource{ 30 | return ^(id dataSource){ 31 | self.dataSource = dataSource; 32 | return self; 33 | }; 34 | } 35 | 36 | - (UITableView *(^)(id))Delegate{ 37 | return ^(id delegate){ 38 | self.delegate = delegate; 39 | return self; 40 | }; 41 | } 42 | 43 | - (UITableView *(^)(CGFloat))RowHeight { 44 | return ^(CGFloat height){ 45 | self.rowHeight = height; 46 | return self; 47 | }; 48 | } 49 | 50 | - (UITableView *(^)(CGFloat))sectionHeadHeight { 51 | return ^(CGFloat height){ 52 | self.sectionHeaderHeight = height; 53 | return self; 54 | }; 55 | } 56 | 57 | - (UITableView *(^)(CGFloat))sectionFootHeight { 58 | return ^(CGFloat height){ 59 | self.sectionFooterHeight = height; 60 | return self; 61 | }; 62 | } 63 | 64 | - (UITableView *(^)(CGFloat))estimateRowHeight { 65 | return ^(CGFloat height){ 66 | self.estimatedRowHeight = height; 67 | return self; 68 | }; 69 | } 70 | 71 | - (UITableView *(^)(UIEdgeInsets))separatInset { 72 | return ^(UIEdgeInsets inset) { 73 | self.separatorInset = inset; 74 | return self; 75 | }; 76 | } 77 | 78 | - (UITableView *(^)(UIView *))bgView { 79 | return ^(UIView *view) { 80 | self.backgroundView = view; 81 | return self; 82 | }; 83 | } 84 | 85 | - (UITableView *(^)(BOOL))edit { 86 | return ^(BOOL b) { 87 | self.editing = b; 88 | return self; 89 | }; 90 | } 91 | 92 | - (UITableView *(^)(BOOL))allowSelect { 93 | return ^(BOOL b) { 94 | self.allowsSelection = b; 95 | return self; 96 | }; 97 | } 98 | - (UITableView *(^)(BOOL))allowMultSelect { 99 | return ^(BOOL b) { 100 | self.allowsMultipleSelection = b; 101 | return self; 102 | }; 103 | } 104 | - (UITableView *(^)(BOOL))allowSelectDuringEdit { 105 | return ^(BOOL b) { 106 | self.allowsSelectionDuringEditing = b; 107 | return self; 108 | }; 109 | } 110 | - (UITableView *(^)(BOOL))allowMultSelectDuringEdit { 111 | return ^(BOOL b) { 112 | self.allowsMultipleSelectionDuringEditing = b; 113 | return self; 114 | }; 115 | } 116 | 117 | - (UITableView *(^)(UIColor *))SectionIndexColor { 118 | return ^(UIColor *color) { 119 | self.sectionIndexColor = color; 120 | return self; 121 | }; 122 | } 123 | 124 | - (UITableView *(^)(UIColor *))sectionIndexBgColor { 125 | return ^(UIColor *color) { 126 | self.sectionIndexBackgroundColor = color; 127 | return self; 128 | }; 129 | } 130 | 131 | - (UITableView *(^)(UIColor *))sectionIndexTrackBgColor { 132 | return ^(UIColor *color) { 133 | self.sectionIndexTrackingBackgroundColor = color; 134 | return self; 135 | }; 136 | } 137 | 138 | - (UITableView *(^)(UITableViewCellSeparatorStyle))separatStyle { 139 | return ^(UITableViewCellSeparatorStyle style) { 140 | self.separatorStyle = style; 141 | return self; 142 | }; 143 | } 144 | 145 | - (UITableView *(^)(UIColor *))separatColor { 146 | return ^(UIColor *color) { 147 | self.separatorColor = color; 148 | return self; 149 | }; 150 | } 151 | 152 | 153 | - (UITableView *(^)(NSIndexPath *, UITableViewScrollPosition, BOOL))scrollToIndexPathAtPositionAnimated { 154 | return ^(NSIndexPath *indexPath, UITableViewScrollPosition position, BOOL b){ 155 | [self scrollToRowAtIndexPath:indexPath atScrollPosition:position animated:b]; 156 | return self; 157 | }; 158 | } 159 | 160 | - (UITableView *(^)(NSIndexSet *, UITableViewRowAnimation))reloadSectionsWithAnimation { 161 | return ^(NSIndexSet *sections, UITableViewRowAnimation animation){ 162 | [self reloadSections:sections withRowAnimation:animation]; 163 | return self; 164 | }; 165 | } 166 | 167 | - (UITableView *(^)(NSArray *, UITableViewRowAnimation))reloadRowsAtIndexPathsWithAnimation { 168 | return ^(NSArray *indexPaths, UITableViewRowAnimation aniamtion){ 169 | [self reloadRowsAtIndexPaths:indexPaths withRowAnimation:aniamtion]; 170 | return self; 171 | }; 172 | } 173 | 174 | - (UITableView *(^)(NSIndexPath *, NSIndexPath *))moveRowAtIndexPathToIndexPath { 175 | return ^(NSIndexPath *fromIndexPath, NSIndexPath *toIndexPath){ 176 | [self moveRowAtIndexPath:fromIndexPath toIndexPath:toIndexPath]; 177 | return self; 178 | }; 179 | } 180 | 181 | - (UITableView *(^)(NSIndexPath *, BOOL, UITableViewScrollPosition))selecRowAtIndexPathAnimatedScrollPosition { 182 | return ^(NSIndexPath *indexPath, BOOL b, UITableViewScrollPosition position){ 183 | [self selectRowAtIndexPath:indexPath animated:b scrollPosition:position]; 184 | return self; 185 | }; 186 | } 187 | 188 | 189 | - (UITableView *(^)(NSIndexPath *, BOOL))deselecRowAtIndexPathAnimated { 190 | return ^(NSIndexPath *indexPath, BOOL b){ 191 | [self deselectRowAtIndexPath:indexPath animated:b]; 192 | return self; 193 | }; 194 | } 195 | 196 | - (UITableView *(^)(BOOL, BOOL))setEditingAnimated { 197 | return ^(BOOL b1, BOOL b2){ 198 | [self setEditing:b1 animated:b2]; 199 | return self; 200 | }; 201 | } 202 | 203 | - (UITableView *(^)(UINib *, NSString *))registNibForCellId { 204 | return ^(UINib *nib, NSString *Id){ 205 | [self registerNib:nib forCellReuseIdentifier:Id]; 206 | return self; 207 | }; 208 | } 209 | 210 | - (UITableView *(^)(Class, NSString *))registClassForCellId { 211 | return ^(Class class, NSString *Id){ 212 | [self registerClass:class forCellReuseIdentifier:Id]; 213 | return self; 214 | }; 215 | } 216 | 217 | 218 | - (UITableView *(^)(UINib *, NSString *))registNibForHeadFootViewId { 219 | return ^(UINib *nib, NSString *Id){ 220 | [self registerNib:nib forHeaderFooterViewReuseIdentifier:Id]; 221 | return self; 222 | }; 223 | } 224 | 225 | - (UITableView *(^)(Class, NSString *))registClassForHeadFootViewId { 226 | return ^(Class class, NSString *Id){ 227 | [self registerClass:class forHeaderFooterViewReuseIdentifier:Id]; 228 | return self; 229 | }; 230 | } 231 | 232 | - (NSInteger (^)(NSInteger))numOfRowsInSection { 233 | return ^(NSInteger secion){ 234 | return [self numberOfRowsInSection:secion]; 235 | }; 236 | } 237 | 238 | - (NSIndexPath *(^)(CGPoint))indexPathForRowAtPoint { 239 | return ^(CGPoint point){ 240 | return [self indexPathForRowAtPoint:point]; 241 | }; 242 | } 243 | 244 | - (NSIndexPath *(^)(UITableViewCell *))indexPathForCell { 245 | return ^(UITableViewCell *cell){ 246 | return [self indexPathForCell:cell]; 247 | }; 248 | } 249 | 250 | - (NSArray *(^)(CGRect))indexPathsForRowsInRect { 251 | return ^(CGRect rect){ 252 | return [self indexPathsForRowsInRect:rect]; 253 | }; 254 | } 255 | 256 | - (UITableViewCell *(^)(NSIndexPath *))cellForRowAtIndexPath { 257 | return ^(NSIndexPath *indexPath){ 258 | return [self cellForRowAtIndexPath:indexPath]; 259 | }; 260 | } 261 | 262 | - (UITableViewCell *(^)(NSString *))dequeueReuseCellWithId { 263 | return ^(NSString *Id){ 264 | return [self dequeueReusableCellWithIdentifier:Id]; 265 | }; 266 | } 267 | 268 | - (UITableViewCell *(^)(NSString *, NSIndexPath *))dequeueReuseCellWithIdForIndexPath { 269 | return ^(NSString *Id, NSIndexPath *indexPath){ 270 | return [self dequeueReusableCellWithIdentifier:Id forIndexPath:indexPath]; 271 | }; 272 | } 273 | 274 | - (UITableViewHeaderFooterView *(^)(NSInteger))headViewForSection { 275 | return ^(NSInteger section){ 276 | return [self headerViewForSection:section]; 277 | }; 278 | } 279 | 280 | - (UITableViewHeaderFooterView *(^)(NSInteger))footViewForSection { 281 | return ^(NSInteger section){ 282 | return [self footerViewForSection:section]; 283 | }; 284 | } 285 | 286 | - (UITableViewHeaderFooterView *(^)(NSString *))dequeueReuseHeadFootViewWithId { 287 | return ^(NSString *Id){ 288 | return [self dequeueReusableHeaderFooterViewWithIdentifier:Id]; 289 | }; 290 | } 291 | 292 | @end 293 | -------------------------------------------------------------------------------- /XRCategory/UITextField+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UITextField (XRCategory) 11 | + (instancetype)create:(void(^)(UITextField *obj))block; 12 | 13 | 14 | //text 15 | @property (nonatomic, strong, readonly) UITextField *(^Text)(NSString *); 16 | @property (nonatomic, strong, readonly) UITextField *(^attributeTxt)(NSAttributedString *); 17 | @property (nonatomic, strong, readonly) UITextField *(^TextColor)(UIColor *); 18 | 19 | //font 20 | @property (nonatomic, strong, readonly) UITextField *(^Font)(UIFont *); 21 | @property (nonatomic, strong, readonly) UITextField *(^fontSize)(NSInteger); 22 | 23 | @property (nonatomic, strong, readonly) UITextField *(^TextAlignment)(NSTextAlignment); 24 | @property (nonatomic, strong, readonly) UITextField *(^BorderStyle)(UITextBorderStyle); 25 | @property (nonatomic, strong, readonly) UITextField *(^defaultTxtAttributes)(NSDictionary *); 26 | 27 | //placeholder 28 | @property (nonatomic, strong, readonly) UITextField *(^placeHolder)(NSString *); 29 | @property (nonatomic, strong, readonly) UITextField *(^attributePlaceholder)(NSAttributedString *); 30 | @property (nonatomic, strong, readonly) UITextField *(^clearOnBeginEdit)(BOOL); 31 | 32 | //adjustsFontSizeToFitWidth 33 | @property (nonatomic, strong, readonly) UITextField *(^adjustFontToWidth)(BOOL); 34 | @property (nonatomic, strong, readonly) UITextField *(^Delegate)(id); 35 | 36 | //background 37 | @property (nonatomic, strong, readonly) UITextField *(^bgImage)(UIImage *); 38 | //disableBackground 39 | @property (nonatomic, strong, readonly) UITextField *(^disableBgImage)(UIImage *); 40 | 41 | 42 | @property (nonatomic, strong, readonly) UITextField *(^allowEditTxtAttribute)(BOOL); 43 | @property (nonatomic, strong, readonly) UITextField *(^clearBtnMode)(UITextFieldViewMode); 44 | 45 | //leftView 46 | @property (nonatomic, strong, readonly) UITextField *(^leftV)(UIView *); 47 | //leftViewMode 48 | @property (nonatomic, strong, readonly) UITextField *(^leftVMode)(UITextFieldViewMode); 49 | //rightView 50 | @property (nonatomic, strong, readonly) UITextField *(^rightV)(UIView *); 51 | //rightViewMode 52 | @property (nonatomic, strong, readonly) UITextField *(^rightVMode)(UITextFieldViewMode); 53 | 54 | //drawPlaceholderInRect 55 | @property (nonatomic, strong, readonly) UITextField *(^drawPlaceholder)(CGRect); 56 | //drawTextInRect 57 | @property (nonatomic, strong, readonly) UITextField *(^drawText)(CGRect); 58 | 59 | //inputView 60 | @property (nonatomic, strong, readonly) UITextField *(^inputV)(UIView *); 61 | //inputAccessoryView 62 | @property (nonatomic, strong, readonly) UITextField *(^inputAccessoryV)(UIView *); 63 | @end 64 | -------------------------------------------------------------------------------- /XRCategory/UITextField+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UITextField+XRCategory.h" 9 | 10 | @implementation UITextField (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UITextField *))block{ 13 | UITextField *obj = [[UITextField alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | - (UITextField *(^)(NSString *))Text{ 19 | return ^(NSString *text){ 20 | self.text = text; 21 | return self; 22 | }; 23 | } 24 | 25 | - (UITextField *(^)(NSAttributedString *))attributeTxt{ 26 | return ^(NSAttributedString *text){ 27 | self.attributedText = text; 28 | return self; 29 | }; 30 | } 31 | 32 | - (UITextField *(^)(UIColor *))TextColor{ 33 | return ^(UIColor *color){ 34 | self.textColor = color; 35 | return self; 36 | }; 37 | } 38 | 39 | - (UITextField *(^)(UIFont *))Font{ 40 | return ^(UIFont *font){ 41 | self.font = font; 42 | return self; 43 | }; 44 | } 45 | 46 | - (UITextField *(^)(NSInteger))fontSize{ 47 | return ^(NSInteger size){ 48 | self.font = [UIFont systemFontOfSize:size]; 49 | return self; 50 | }; 51 | } 52 | 53 | - (UITextField *(^)(NSTextAlignment))TextAlignment{ 54 | return ^(NSTextAlignment alignment){ 55 | self.textAlignment = alignment; 56 | return self; 57 | }; 58 | } 59 | 60 | - (UITextField *(^)(UITextBorderStyle))BorderStyle{ 61 | return ^(UITextBorderStyle style){ 62 | self.borderStyle= style; 63 | return self; 64 | }; 65 | } 66 | 67 | - (UITextField *(^)(NSDictionary *))defaultTxtAttributes{ 68 | return ^(NSDictionary *attributes){ 69 | self.defaultTextAttributes = attributes; 70 | return self; 71 | }; 72 | } 73 | 74 | - (UITextField *(^)(NSString *))placeHolder{ 75 | return ^(NSString *text){ 76 | self.placeholder = text; 77 | return self; 78 | }; 79 | } 80 | 81 | - (UITextField *(^)(NSAttributedString *))attributePlaceholder{ 82 | return ^(NSAttributedString *text){ 83 | self.attributedPlaceholder = text; 84 | return self; 85 | }; 86 | } 87 | 88 | - (UITextField *(^)(BOOL))clearOnBeginEdit{ 89 | return ^(BOOL b){ 90 | self.clearsOnBeginEditing = b; 91 | return self; 92 | }; 93 | } 94 | 95 | - (UITextField *(^)(BOOL))adjustFontToWidth{ 96 | return ^(BOOL b){ 97 | self.adjustsFontSizeToFitWidth = b; 98 | return self; 99 | }; 100 | } 101 | 102 | - (UITextField *(^)(id))Delegate { 103 | return ^(id delegate) { 104 | self.delegate = delegate; 105 | return self; 106 | }; 107 | } 108 | 109 | - (UITextField *(^)(UIImage *))bgImage { 110 | return ^(UIImage *image){ 111 | self.background = image; 112 | return self; 113 | }; 114 | } 115 | 116 | - (UITextField *(^)(UIImage *))disableBgImage { 117 | return ^(UIImage *image){ 118 | self.disabledBackground = image; 119 | return self; 120 | }; 121 | } 122 | 123 | 124 | - (UITextField *(^)(BOOL))allowEditTxtAttribute { 125 | return ^(BOOL b){ 126 | self.allowsEditingTextAttributes = b; 127 | return self; 128 | }; 129 | } 130 | 131 | - (UITextField *(^)(UITextFieldViewMode))clearBtnMode { 132 | return ^(UITextFieldViewMode mode){ 133 | self.clearButtonMode = mode; 134 | return self; 135 | }; 136 | } 137 | 138 | - (UITextField *(^)(UIView *))leftV { 139 | return ^(UIView *view){ 140 | self.leftView = view; 141 | return self; 142 | }; 143 | } 144 | 145 | - (UITextField *(^)(UITextFieldViewMode))leftVMode { 146 | return ^(UITextFieldViewMode mode){ 147 | self.leftViewMode = mode; 148 | return self; 149 | }; 150 | } 151 | 152 | - (UITextField *(^)(UIView *))rightV { 153 | return ^(UIView *view){ 154 | self.rightView = view; 155 | return self; 156 | }; 157 | } 158 | 159 | - (UITextField *(^)(UITextFieldViewMode))rightVMode { 160 | return ^(UITextFieldViewMode mode){ 161 | self.rightViewMode = mode; 162 | return self; 163 | }; 164 | } 165 | 166 | - (UITextField *(^)(CGRect))drawPlaceholder { 167 | return ^(CGRect rect){ 168 | [self drawPlaceholderInRect:rect]; 169 | return self; 170 | }; 171 | } 172 | 173 | - (UITextField *(^)(CGRect))drawText { 174 | return ^(CGRect rect){ 175 | [self drawTextInRect:rect]; 176 | return self; 177 | }; 178 | } 179 | 180 | - (UITextField *(^)(UIView *))inputV { 181 | return ^(UIView *view){ 182 | self.inputView = view; 183 | return self; 184 | }; 185 | } 186 | 187 | - (UITextField *(^)(UIView *))inputAccessoryV { 188 | return ^(UIView *view){ 189 | self.inputAccessoryView = view; 190 | return self; 191 | }; 192 | } 193 | @end 194 | -------------------------------------------------------------------------------- /XRCategory/UITextView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UITextView (XRCategory) 11 | 12 | + (instancetype)create:(void(^)(UITextView *obj))block; 13 | 14 | //text 15 | @property (nonatomic, strong, readonly) UITextView *(^Text)(NSString *); 16 | @property (nonatomic, strong, readonly) UITextView *(^attributeTxt)(NSAttributedString *); 17 | @property (nonatomic, strong, readonly) UITextView *(^TextColor)(UIColor *); 18 | 19 | //font 20 | @property (nonatomic, strong, readonly) UITextView *(^Font)(UIFont *); 21 | @property (nonatomic, strong, readonly) UITextView *(^fontSize)(NSInteger); 22 | 23 | @property (nonatomic, strong, readonly) UITextView *(^TextAlignment)(NSTextAlignment); 24 | @property (nonatomic, strong, readonly) UITextView *(^Delegate)(id); 25 | @property (nonatomic, strong, readonly) UITextView *(^allowEditTxtAttribute)(BOOL); 26 | 27 | //inputView 28 | @property (nonatomic, strong, readonly) UITextView *(^inputV)(UIView *); 29 | //inputAccessoryView 30 | @property (nonatomic, strong, readonly) UITextView *(^inputAccessoryV)(UIView *); 31 | 32 | 33 | @property (nonatomic, strong, readonly) UITextView *(^selectRange)(NSRange); 34 | @property (nonatomic, strong, readonly) UITextView *(^editAble)(BOOL); 35 | @property (nonatomic, strong, readonly) UITextView *(^selectAble)(BOOL); 36 | @property (nonatomic, strong, readonly) UITextView *(^dataDetectorType)(UIDataDetectorTypes); 37 | @property (nonatomic, strong, readonly) UITextView *(^txtContainerInset)(UIEdgeInsets); 38 | @property (nonatomic, strong, readonly) UITextView *(^linkTxtAttributes)(NSDictionary *); 39 | @property (nonatomic, strong, readonly) UITextView *(^scrollRangeToVisible)(NSRange); 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /XRCategory/UITextView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UITextView+XRCategory.h" 9 | 10 | @implementation UITextView (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UITextView *))block{ 13 | UITextView *obj = [[UITextView alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | 19 | - (UITextView *(^)(NSString *))Text{ 20 | return ^(NSString *text){ 21 | self.text = text; 22 | return self; 23 | }; 24 | } 25 | 26 | - (UITextView *(^)(NSAttributedString *))attributeTxt{ 27 | return ^(NSAttributedString *text){ 28 | self.attributedText = text; 29 | return self; 30 | }; 31 | } 32 | 33 | - (UITextView *(^)(UIColor *))TextColor{ 34 | return ^(UIColor *color){ 35 | self.textColor = color; 36 | return self; 37 | }; 38 | } 39 | 40 | - (UITextView *(^)(UIFont *))Font{ 41 | return ^(UIFont *font){ 42 | self.font = font; 43 | return self; 44 | }; 45 | } 46 | 47 | - (UITextView *(^)(NSInteger))fontSize{ 48 | return ^(NSInteger size){ 49 | self.font = [UIFont systemFontOfSize:size]; 50 | return self; 51 | }; 52 | } 53 | 54 | - (UITextView *(^)(NSTextAlignment))TextAlignment{ 55 | return ^(NSTextAlignment alignment){ 56 | self.textAlignment = alignment; 57 | return self; 58 | }; 59 | } 60 | 61 | - (UITextView *(^)(id))Delegate { 62 | return ^(id delegate) { 63 | self.delegate = delegate; 64 | return self; 65 | }; 66 | } 67 | 68 | - (UITextView *(^)(BOOL))allowEditTxtAttribute { 69 | return ^(BOOL b){ 70 | self.allowsEditingTextAttributes = b; 71 | return self; 72 | }; 73 | } 74 | 75 | - (UITextView *(^)(UIView *))inputV { 76 | return ^(UIView *view){ 77 | self.inputView = view; 78 | return self; 79 | }; 80 | } 81 | 82 | - (UITextView *(^)(UIView *))inputAccessoryV { 83 | return ^(UIView *view){ 84 | self.inputAccessoryView = view; 85 | return self; 86 | }; 87 | } 88 | 89 | - (UITextView *(^)(NSRange))selectRange { 90 | return ^(NSRange range){ 91 | self.selectedRange = range; 92 | return self; 93 | }; 94 | } 95 | 96 | - (UITextView *(^)(BOOL))editAble { 97 | return ^(BOOL b){ 98 | self.editable = b; 99 | return self; 100 | }; 101 | } 102 | 103 | - (UITextView *(^)(BOOL))selectAble { 104 | return ^(BOOL b){ 105 | self.selectable = b; 106 | return self; 107 | }; 108 | } 109 | 110 | - (UITextView *(^)(UIDataDetectorTypes))dataDetectorType { 111 | return ^(UIDataDetectorTypes type){ 112 | self.dataDetectorTypes = type; 113 | return self; 114 | }; 115 | } 116 | 117 | - (UITextView *(^)(UIEdgeInsets))txtContainerInset { 118 | return ^(UIEdgeInsets edge){ 119 | self.textContainerInset = edge; 120 | return self; 121 | }; 122 | } 123 | 124 | - (UITextView *(^)(NSDictionary *))linkTxtAttributes { 125 | return ^(NSDictionary *attributes){ 126 | self.linkTextAttributes = attributes; 127 | return self; 128 | }; 129 | } 130 | 131 | - (UITextView *(^)(NSRange))scrollRangeToVisible { 132 | return ^(NSRange range){ 133 | [self scrollRangeToVisible:range]; 134 | return self; 135 | }; 136 | } 137 | @end 138 | -------------------------------------------------------------------------------- /XRCategory/UIView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/12. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIView (XRCategory) 11 | 12 | + (instancetype)create:(void(^)(UIView *obj))block; 13 | 14 | @property (nonatomic, assign, readonly) CGFloat X; 15 | @property (nonatomic, assign, readonly) CGFloat Y; 16 | @property (nonatomic, assign, readonly) CGFloat Width; 17 | @property (nonatomic, assign, readonly) CGFloat Height; 18 | @property (nonatomic, assign, readonly) CGFloat CenterX; 19 | @property (nonatomic, assign, readonly) CGFloat CenterY; 20 | 21 | @property (nonatomic, strong, readonly) UIView *(^Frame)(CGRect);//frame 22 | @property (nonatomic, strong, readonly) UIView *(^frameEle)(CGFloat, CGFloat, CGFloat, CGFloat);//frame 23 | @property (nonatomic, strong, readonly) UIView *(^x)(CGFloat);//frame.origin.x 24 | @property (nonatomic, strong, readonly) UIView *(^y)(CGFloat);//frame.origin.y 25 | @property (nonatomic, strong, readonly) UIView *(^width)(CGFloat);//frame.origin.width 26 | @property (nonatomic, strong, readonly) UIView *(^height)(CGFloat);//frame.origin.height 27 | @property (nonatomic, strong, readonly) UIView *(^Bounds)(CGRect);//bounds 28 | @property (nonatomic, strong, readonly) UIView *(^boundsEle)(CGFloat, CGFloat, CGFloat, CGFloat);//bounds 29 | @property (nonatomic, strong, readonly) UIView *(^Center)(CGPoint);//center 30 | @property (nonatomic, strong, readonly) UIView *(^centerEle)(CGFloat, CGFloat);//center 31 | @property (nonatomic, strong, readonly) UIView *(^centerX)(CGFloat);//center.x 32 | @property (nonatomic, strong, readonly) UIView *(^centerY)(CGFloat);//center.y 33 | @property (nonatomic, strong, readonly) UIView *(^size)(CGSize);//frame.size 34 | @property (nonatomic, strong, readonly) UIView *(^sizeEle)(CGFloat, CGFloat);//frame.size 35 | @property (nonatomic, strong, readonly) UIView *(^origin)(CGPoint);//frame.origin 36 | @property (nonatomic, strong, readonly) UIView *(^originEle)(CGFloat, CGFloat);//frame.origin 37 | 38 | 39 | @property (nonatomic, strong, readonly) UIView *(^bgColor)(UIColor *);//backgroundColor 40 | @property (nonatomic, strong, readonly) UIView *(^bgColorRGB)(CGFloat, CGFloat, CGFloat, CGFloat);//backgroundColor 41 | @property (nonatomic, strong, readonly) UIView *(^Alpha)(CGFloat); 42 | @property (nonatomic, strong, readonly) UIView *(^Opaque)(CGFloat); 43 | @property (nonatomic, strong, readonly) UIView *(^cornerRadius)(CGFloat); 44 | @property (nonatomic, strong, readonly) UIView *(^maskToBounds)(BOOL); 45 | @property (nonatomic, strong, readonly) UIView *(^clipToBounds)(BOOL ); 46 | @property (nonatomic, strong, readonly) UIView *(^userInteractionEnable)(BOOL); 47 | @property (nonatomic, strong, readonly) UIView *(^hide)(BOOL); 48 | @property (nonatomic, strong, readonly) UIView *(^Tag)(NSInteger); 49 | @property (nonatomic, strong, readonly) UIView *(^ContentMode)(UIViewContentMode); 50 | @property (nonatomic, strong, readonly) UIView *(^multipleTouch)(BOOL); 51 | @property (nonatomic, strong, readonly) UIView *(^autoresizeSubViews)(BOOL); 52 | @property (nonatomic, strong, readonly) UIView *(^autoresizeMask)(BOOL); 53 | @property (nonatomic, strong, readonly) UIView *(^endEdit)(BOOL); 54 | 55 | @property (nonatomic, strong, readonly) UIView *(^removeFromSuperView)(); 56 | @property (nonatomic, strong, readonly) UIView *(^insertSubviewAtIndex)(UIView *, NSInteger); 57 | @property (nonatomic, strong, readonly) UIView *(^exchangeSubviewAtIndexWithIndex)(NSInteger, NSInteger); 58 | @property (nonatomic, strong, readonly) UIView *(^addSubview)(UIView *); 59 | @property (nonatomic, strong, readonly) UIView *(^insertSubviewBelowView)(UIView *, UIView *); 60 | @property (nonatomic, strong, readonly) UIView *(^insertSubviewAboveView)(UIView *, UIView *); 61 | @property (nonatomic, strong, readonly) UIView *(^bringSubviewToFront)(UIView *); 62 | @property (nonatomic, strong, readonly) UIView *(^sendSubviewToBack)(UIView *); 63 | 64 | 65 | /** 66 | * addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer 67 | * 68 | */ 69 | @property (nonatomic, strong, readonly) UIView *(^addGesture)(UIGestureRecognizer *); 70 | 71 | 72 | /** 73 | * removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer 74 | * 75 | */ 76 | @property (nonatomic, strong, readonly) UIView *(^removeGesture)(UIGestureRecognizer *); 77 | 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /XRCategory/UIView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/12. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIView+XRCategory.h" 9 | 10 | @implementation UIView (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UIView *))block{ 13 | UIView *obj = [[UIView alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | 19 | - (CGFloat)X { 20 | return self.frame.origin.x; 21 | } 22 | 23 | - (CGFloat)Y { 24 | return self.frame.origin.y; 25 | } 26 | 27 | - (CGFloat)Width { 28 | return self.frame.size.width; 29 | } 30 | 31 | - (CGFloat)Height { 32 | return self.frame.size.height; 33 | } 34 | 35 | - (CGFloat)CenterX { 36 | return self.center.x; 37 | } 38 | 39 | - (CGFloat)CenterY { 40 | return self.center.y; 41 | } 42 | 43 | 44 | - (UIView *(^)(CGRect))Frame { 45 | return ^(CGRect frame) { 46 | self.frame = frame; 47 | return self; 48 | }; 49 | } 50 | 51 | - (UIView *(^)(CGFloat, CGFloat, CGFloat, CGFloat))frameEle { 52 | return ^(CGFloat x, CGFloat y, CGFloat width, CGFloat height){ 53 | self.frame = CGRectMake(x, y, width, height); 54 | return self; 55 | }; 56 | } 57 | 58 | - (UIView *(^)(CGFloat))x { 59 | return ^(CGFloat x) { 60 | CGRect frame = self.frame; 61 | frame.origin.x = x; 62 | self.frame = frame; 63 | return self; 64 | }; 65 | } 66 | 67 | - (UIView *(^)(CGFloat))y { 68 | return ^(CGFloat y) { 69 | CGRect frame = self.frame; 70 | frame.origin.y = y; 71 | self.frame = frame; 72 | return self; 73 | }; 74 | } 75 | 76 | - (UIView *(^)(CGFloat))width { 77 | return ^(CGFloat width) { 78 | CGRect frame = self.frame; 79 | frame.size.width = width; 80 | self.frame = frame; 81 | return self; 82 | }; 83 | } 84 | 85 | - (UIView *(^)(CGFloat))height { 86 | return ^(CGFloat height) { 87 | CGRect frame = self.frame; 88 | frame.size.height = height; 89 | self.frame = frame; 90 | return self; 91 | }; 92 | } 93 | 94 | - (UIView *(^)(CGRect bounds))Bounds { 95 | return ^(CGRect bounds) { 96 | self.bounds = bounds; 97 | return self; 98 | }; 99 | } 100 | - (UIView *(^)(CGFloat x, CGFloat y, CGFloat width, CGFloat height))boundsEle { 101 | return ^(CGFloat x, CGFloat y, CGFloat width, CGFloat height){ 102 | self.bounds = CGRectMake(x, y, width, height); 103 | return self; 104 | }; 105 | } 106 | 107 | - (UIView *(^)(CGPoint center))Center { 108 | return ^(CGPoint center){ 109 | self.center = center; 110 | return self; 111 | }; 112 | } 113 | 114 | - (UIView *(^)(CGFloat x, CGFloat y))centerEle { 115 | return ^(CGFloat x, CGFloat y){ 116 | self.center = CGPointMake(x, y); 117 | return self; 118 | }; 119 | } 120 | 121 | - (UIView *(^)(CGFloat))centerX { 122 | return ^(CGFloat centerX) { 123 | CGPoint center = self.center; 124 | center.x = centerX; 125 | self.center = center; 126 | return self; 127 | }; 128 | } 129 | 130 | - (UIView *(^)(CGFloat))centerY { 131 | return ^(CGFloat centerY) { 132 | CGPoint center = self.center; 133 | center.y = centerY; 134 | self.center = center; 135 | return self; 136 | }; 137 | } 138 | 139 | - (UIView *(^)(CGSize size))size { 140 | return ^(CGSize size){ 141 | CGRect frame = self.frame; 142 | frame.size = size; 143 | self.frame = frame; 144 | return self; 145 | }; 146 | } 147 | 148 | - (UIView *(^)(CGFloat width, CGFloat height))sizeEle { 149 | return ^(CGFloat width, CGFloat height){ 150 | CGRect frame = self.frame; 151 | frame.size = CGSizeMake(width, height); 152 | self.frame = frame; 153 | return self; 154 | }; 155 | } 156 | 157 | - (UIView *(^)(CGPoint origin))origin { 158 | return ^(CGPoint origin){ 159 | CGRect frame = self.frame; 160 | frame.origin = origin; 161 | self.frame = frame; 162 | return self; 163 | }; 164 | } 165 | 166 | - (UIView *(^)(CGFloat x, CGFloat y))originEle { 167 | return ^(CGFloat x, CGFloat y){ 168 | CGRect frame = self.frame; 169 | frame.origin = CGPointMake(x, y); 170 | self.frame = frame; 171 | return self; 172 | }; 173 | } 174 | 175 | - (UIView *(^)(UIColor *))bgColor { 176 | return ^(UIColor *color) { 177 | self.backgroundColor = color; 178 | return self; 179 | }; 180 | } 181 | 182 | - (UIView *(^)(CGFloat, CGFloat, CGFloat, CGFloat))bgColorRGB { 183 | return ^(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha){ 184 | self.backgroundColor = [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:alpha]; 185 | return self; 186 | }; 187 | } 188 | 189 | - (UIView *(^)(CGFloat))Alpha { 190 | return ^(CGFloat alpha) { 191 | self.alpha = alpha; 192 | return self; 193 | }; 194 | } 195 | 196 | - (UIView *(^)(CGFloat))Opaque { 197 | return ^(CGFloat opaque) { 198 | self.opaque = opaque; 199 | return self; 200 | }; 201 | } 202 | 203 | - (UIView *(^)(CGFloat))cornerRadius { 204 | return ^(CGFloat radius) { 205 | self.layer.cornerRadius = radius; 206 | return self; 207 | }; 208 | } 209 | 210 | - (UIView *(^)(BOOL))maskToBounds { 211 | return ^(BOOL b) { 212 | self.layer.masksToBounds = b; 213 | return self; 214 | }; 215 | } 216 | 217 | - (UIView *(^)(BOOL))clipToBounds { 218 | return ^(BOOL b) { 219 | self.clipsToBounds = b; 220 | return self; 221 | }; 222 | } 223 | 224 | - (UIView *(^)(BOOL))userInteractionEnable { 225 | return ^(BOOL b) { 226 | self.userInteractionEnabled = b; 227 | return self; 228 | }; 229 | } 230 | 231 | - (UIView *(^)(BOOL))hide{ 232 | return ^(BOOL b) { 233 | self.hidden = b; 234 | return self; 235 | }; 236 | } 237 | 238 | - (UIView *(^)(NSInteger))Tag { 239 | return ^(NSInteger tag){ 240 | self.tag = tag; 241 | return self; 242 | }; 243 | } 244 | 245 | 246 | - (UIView *(^)(UIViewContentMode))ContentMode { 247 | return ^(UIViewContentMode mode){ 248 | self.contentMode = mode; 249 | return self; 250 | }; 251 | } 252 | 253 | - (UIView *(^)(BOOL))multipleTouch { 254 | return ^(BOOL b) { 255 | self.multipleTouchEnabled = b; 256 | return self; 257 | }; 258 | } 259 | 260 | - (UIView *(^)(BOOL))autoresizeSubViews { 261 | return ^(BOOL b) { 262 | self.autoresizesSubviews = b; 263 | return self; 264 | }; 265 | } 266 | 267 | - (UIView *(^)(BOOL))autoresizeMask { 268 | return ^(BOOL b) { 269 | self.autoresizingMask = b; 270 | return self; 271 | }; 272 | } 273 | 274 | 275 | - (UIView *(^)(BOOL))endEdit { 276 | return ^(BOOL b){ 277 | [self endEditing:b]; 278 | return self; 279 | }; 280 | } 281 | 282 | 283 | - (UIView *(^)())removeFromSuperView { 284 | return ^(){ 285 | [self removeFromSuperview]; 286 | return self; 287 | }; 288 | } 289 | 290 | - (UIView *(^)(UIView *, NSInteger))insertSubviewAtIndex { 291 | return ^(UIView *view, NSInteger index) { 292 | [self insertSubview:view atIndex:index]; 293 | return self; 294 | }; 295 | } 296 | 297 | - (UIView *(^)(UIView *, UIView *))insertSubviewBelowView { 298 | return ^(UIView *view1, UIView *view2) { 299 | [self insertSubview:view1 belowSubview:view2]; 300 | return self; 301 | }; 302 | } 303 | 304 | - (UIView *(^)(UIView *, UIView *))insertSubviewAboveView { 305 | return ^(UIView *view1, UIView *view2) { 306 | [self insertSubview:view1 aboveSubview:view2]; 307 | return self; 308 | }; 309 | } 310 | 311 | - (UIView *(^)(NSInteger , NSInteger))exchangeSubviewAtIndexWithIndex { 312 | return ^(NSInteger index1, NSInteger index2) { 313 | [self exchangeSubviewAtIndex:index1 withSubviewAtIndex:index2]; 314 | return self; 315 | }; 316 | } 317 | 318 | - (UIView *(^)(UIView *))addSubview { 319 | return ^(UIView *view) { 320 | [self addSubview:view]; 321 | return self; 322 | }; 323 | } 324 | 325 | - (UIView *(^)(UIView *))bringSubviewToFront { 326 | return ^(UIView *view) { 327 | [self bringSubviewToFront:view]; 328 | return self; 329 | }; 330 | } 331 | 332 | - (UIView *(^)(UIView *))sendSubviewToBack { 333 | return ^(UIView *view) { 334 | [self sendSubviewToBack:view]; 335 | return self; 336 | }; 337 | } 338 | 339 | - (UIView *(^)(UIGestureRecognizer *))addGesture { 340 | return ^(UIGestureRecognizer *gesture){ 341 | [self addGestureRecognizer:gesture]; 342 | return self; 343 | }; 344 | } 345 | 346 | - (UIView *(^)(UIGestureRecognizer *))removeGesture { 347 | return ^(UIGestureRecognizer *gesture){ 348 | [self removeGestureRecognizer:gesture]; 349 | return self; 350 | }; 351 | } 352 | @end 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | -------------------------------------------------------------------------------- /XRCategory/XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #ifndef XRCategory_h 10 | #define XRCategory_h 11 | #import "NSObject+XRCategory.h" 12 | #import "UIView+XRCategory.h" 13 | #import "UIControl+XRCategory.h" 14 | #import "UIButton+XRCategory.h" 15 | #import "UIImageView+XRCategory.h" 16 | #import "UILabel+XRCategory.h" 17 | #import "UIScrollView+XRCategory.h" 18 | #import "UITableView+XRCategory.h" 19 | #import "UITextField+XRCategory.h" 20 | #import "UITextView+XRCategory.h" 21 | #import "NSArray+XRCategory.h" 22 | #import "NSString+XRCategory.h" 23 | #import "NSDictionary+XRCategory.h" 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Assets.xcassets/icon.imageset/2bumen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingZero/XRCategory/8c42f546a30f111f9a9bbb03b74baac7f6c8dc27/XRCategoryDemo/XRCategoryDemo/Assets.xcassets/icon.imageset/2bumen.png -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Assets.xcassets/icon.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "2bumen.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Person.h: -------------------------------------------------------------------------------- 1 | // 2 | // Person.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface Person : NSObject 12 | @property (nonatomic, strong) NSString *name; 13 | @property (nonatomic, assign) NSInteger age; 14 | 15 | - (void)eat:(NSString *)str; 16 | @end 17 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/Person.m: -------------------------------------------------------------------------------- 1 | // 2 | // Person.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "Person.h" 10 | 11 | @implementation Person 12 | 13 | - (void)eat:(NSString *)str { 14 | NSLog(@"吃了%@", str); 15 | } 16 | @end 17 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "XRCategory.h" 11 | #import "Person.h" 12 | @interface ViewController () 13 | @property (nonatomic, weak) UIScrollView *scrollView; 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | [self NSObject]; 21 | [self UIScrollView]; 22 | [self UIView]; 23 | [self UIButton]; 24 | [self UILabel]; 25 | [self UIImageView]; 26 | [self UITextField]; 27 | [self UITableView]; 28 | [self NSString]; 29 | [self NSArray]; 30 | [self NSDictionary]; 31 | 32 | } 33 | 34 | 35 | - (void)NSObject { 36 | [Person create:^(Person *obj) { 37 | obj.setValueForKey(@"张三", @"name"); 38 | obj.setValueForKeyPath(@12, @"age"); 39 | NSLog(@"%@", obj.valueForKey(@"name")); 40 | NSLog(@"%@", obj.valueForKeyPath(@"age")); 41 | NSLog(@"%d", obj.isKindOfClass([Person class])); 42 | if (obj.respondsToSelector(@selector(eat:))) { 43 | obj.performSelOnMainThread(@selector(eat:), @"苹果", YES); 44 | } 45 | }]; 46 | } 47 | 48 | 49 | - (void)UIView { 50 | UIView *view = [UIView create:^(UIView *obj) { 51 | // obj.originEle(0, 0).sizeEle(self.view.Width, self.view.Height); 52 | // obj.Center(CGPointMake(160, 300)).Bounds(CGRectMake(0, 0, 300, 300)); 53 | // obj.x(0).y(0).width(300).height(300); 54 | obj.Frame(self.view.bounds).bgColorRGB(121, 231, 89, 1).Alpha(0.6).cornerRadius(80).maskToBounds(YES); 55 | }]; 56 | self.scrollView.addSubview(view); 57 | } 58 | 59 | - (void)UIButton { 60 | [UIButton create:^(UIButton *obj) { 61 | obj.centerEle(100, 100).sizeEle(120, 50).bgColor([UIColor blueColor]); 62 | obj.setTitleForState(@"我是按钮", UIControlStateNormal); 63 | obj.setImageForState([UIImage imageNamed:@"icon"], UIControlStateNormal); 64 | obj.cornerRadius(5).maskToBounds(YES); 65 | obj.contentEdgeEle(0, 5, 0, 0).imageEdgeEle(5, 0, 0, 5).titleEdgeEle(0, 5, 5, 0); 66 | obj.adjustImgWhenDisable(NO).adjustImgWhenHighlight(NO); 67 | obj.addTarget(self, @selector(click:), UIControlEventTouchUpInside); 68 | self.scrollView.addSubview(obj); 69 | }]; 70 | } 71 | 72 | 73 | - (void)click:(UIButton *)btn{ 74 | NSString *title = btn.titleForState(UIControlStateNormal); 75 | UIImage *image = btn.imageForState(UIControlStateNormal); 76 | NSLog(@"%@--%@", title, image); 77 | } 78 | 79 | 80 | - (void)UILabel { 81 | [UILabel create:^(UILabel *obj) { 82 | obj.origin(CGPointMake(120, 300)).sizeEle(150, 150); 83 | obj.bgColorRGB(0, 255, 255, 1).Alpha(0.5); 84 | obj.numberOfLine(0).TextAlignment(NSTextAlignmentCenter).LineBreakMode(NSLineBreakByTruncatingHead); 85 | obj.Text(@"我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label我是一个label"); 86 | self.scrollView.addSubview(obj); 87 | }]; 88 | } 89 | 90 | - (void)UIImageView { 91 | UIImageView *imageView = [UIImageView create:^(UIImageView *obj) { 92 | obj.Frame(CGRectMake(20, 200, 100, 100)); 93 | obj.Image([UIImage imageNamed:@"icon"]).cornerRadius(20).clipToBounds(YES); 94 | self.scrollView.addSubview(obj); 95 | }]; 96 | 97 | } 98 | 99 | 100 | - (void)UITextField { 101 | [UITextField create:^(UITextField *obj) { 102 | obj.frameEle(100, 200, 200, 30); 103 | obj.placeHolder(@"占位文字").fontSize(20).TextColor([UIColor redColor]).BorderStyle(UITextBorderStyleRoundedRect); 104 | obj.clearOnBeginEdit(YES).bgImage([UIImage imageNamed:@"icon"]); 105 | obj.leftV([[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)]).leftVMode(UITextFieldViewModeAlways); 106 | self.scrollView.addSubview(obj); 107 | }]; 108 | } 109 | 110 | 111 | - (void)UIScrollView { 112 | UIScrollView *scrollView = [UIScrollView create:^(UIScrollView *obj) { 113 | obj.Frame([UIScreen mainScreen].bounds).bgColor([UIColor whiteColor]); 114 | obj.ContentInset(UIEdgeInsetsMake(10, 10, 10, 10)).ContentSize(CGSizeMake(1000, 2000)).ContentOffset(CGPointMake(50, 100)); 115 | obj.alwaysBounceH(NO).showVIndicator(NO); 116 | obj.Delegate(self); 117 | self.view.addSubview(obj); 118 | }]; 119 | self.scrollView = scrollView; 120 | } 121 | 122 | - (void)UITableView { 123 | [UITableView createWithStyle:UITableViewStyleGrouped :^(UITableView *obj) { 124 | obj.originEle(375, 0).sizeEle(360, 650); 125 | obj.DataSource(self).Delegate(self); 126 | obj.separatStyle(UITableViewCellSeparatorStyleNone); 127 | obj.RowHeight(60).sectionHeadHeight(30).sectionFootHeight(30); 128 | obj.registClassForCellId([UITableViewCell class], @"cell"); 129 | self.scrollView.addSubview(obj); 130 | }]; 131 | } 132 | 133 | - (void)NSString { 134 | [NSString createWithString:@"我是一个字符串,信不信由你" :^(NSString *obj) { 135 | NSLog(@"%@", obj.subStrFromIndex(5)); 136 | NSLog(@"%@", obj.stringByAppendStr(@",这是追加的字符串")); 137 | NSLog(@"%d", obj.hasPrefix(@"我")); 138 | NSLog(@"%@", NSStringFromRange(obj.rangeOfString(@"一个"))); 139 | NSLog(@"%d", obj.isEqualToString(@"我是一个字符串")); 140 | }]; 141 | 142 | [NSMutableString createWithString:@"我是可变的字符串,比上面的牛逼" :^(NSMutableString *obj) { 143 | obj.replaceCharInRange(NSMakeRange(2, 2), @"好可怕"); 144 | obj.insertStrAtIndex(@"插入字符串", 4).appendStr(@"追加字符串").deleteCharInRange(NSMakeRange(3, 5)); 145 | NSLog(@"%@", obj); 146 | }]; 147 | } 148 | 149 | - (void)NSArray { 150 | NSArray *array = @[@"1", @"2", @"3", @"4", @"5"]; 151 | [NSArray createWithArray:array :^(NSArray *obj) { 152 | NSLog(@"%ld", obj.indexOfObject(@"3")); 153 | NSLog(@"%@", obj.objectAtIndex(1)); 154 | NSLog(@"%d", obj.isEqualToArray(array)); 155 | NSLog(@"%@", obj.componentsJoinByStr(@"-")); 156 | NSLog(@"%d", obj.containsObject(@"4")); 157 | obj.makeObjPerformSelWithObj(@selector(stringByAppendingString:), @"aa"); 158 | }]; 159 | 160 | [NSMutableArray create:^(NSMutableArray *obj) { 161 | obj.addObject(@"a").addObject(@"b").addObject(@"c").addObject(@"d").addObject(@"e"); 162 | obj.removeLastObj().removeObjAtIndex(1).insertObjAtIndex(@"f", 3); 163 | obj.exchangeObjAtIndexWithIndex(2,3).replaceObjsInRangeWithObjsFromArray(NSMakeRange(1, 2), @[@"z", @"k"]); 164 | obj.removeObjInRange(@"c" ,NSMakeRange(0, 2)).addObjsFromArray(@[@"t", @"p", @"l"]); 165 | NSLog(@"%@", obj.componentsJoinByStr(@".")); 166 | }]; 167 | } 168 | 169 | - (void)NSDictionary { 170 | [NSDictionary createWithDicdionary:@{@"a" :@"1", @"b" :@"2", @"c" :@"3", @"d" :@"3"} :^(NSDictionary *obj) { 171 | NSLog(@"%@", obj.allKeysForObject(@"3")); 172 | NSLog(@"%@", obj.objectForKey(@"a")); 173 | }]; 174 | 175 | [NSMutableDictionary create:^(NSMutableDictionary *obj) { 176 | obj.setDictionary(@{@"a" :@"1", @"b" :@"2", @"c" :@"3", @"d" :@"3"}); 177 | obj.setObjectForKey(@"4", @"e").setObjectForKey(@"1", @"f").setObjectForKey(@"5", @"g"); 178 | obj.removeObjectForKey(@"b").removeObjsForKeys(@[@"e", @"g"]); 179 | NSLog(@"%@", obj); 180 | }]; 181 | } 182 | 183 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 184 | NSLog(@"滚"); 185 | } 186 | 187 | 188 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 189 | return 3; 190 | } 191 | 192 | 193 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 194 | return 7; 195 | } 196 | 197 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 198 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 199 | cell.textLabel.Text([NSString stringWithFormat:@"%ld", indexPath.row]); 200 | return cell; 201 | } 202 | @end 203 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/NSArray+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (XRCategory) 12 | + (instancetype)createWithArray:(NSArray *)array :(void(^)(NSArray *obj))block; 13 | 14 | @property (nonatomic, strong, readonly) NSArray *(^arrayByAddObject)(id); 15 | @property (nonatomic, strong, readonly) NSArray *(^arrayByAddObjFromArray)(NSArray *); 16 | @property (nonatomic, strong, readonly) NSString *(^componentsJoinByStr)(NSString *); 17 | @property (nonatomic, strong, readonly) BOOL (^containsObject)(id); 18 | @property (nonatomic, strong, readonly) NSUInteger (^indexOfObject)(id); 19 | @property (nonatomic, strong, readonly) NSUInteger (^indexOfObjInRange)(id, NSRange); 20 | @property (nonatomic, strong, readonly) BOOL (^isEqualToArray)(NSArray *); 21 | @property (nonatomic, strong, readonly) BOOL (^writeToFileAtomical)(NSString *, BOOL); 22 | @property (nonatomic, strong, readonly) BOOL (^writeToURLAtomical)(NSURL *, BOOL); 23 | 24 | /** 25 | * makeObjectsPerformSelector:(SEL)aSelector 26 | */ 27 | @property (nonatomic, strong, readonly) NSArray *(^makeObjPerformSel)(SEL); 28 | 29 | /** 30 | * makeObjectsPerformSelector:(SEL)aSelector withObject:(nullable id)argument 31 | */ 32 | @property (nonatomic, strong, readonly) NSArray *(^makeObjPerformSelWithObj)(SEL, id); 33 | 34 | @property (nonatomic, strong, readonly) id (^objectAtIndex)(NSUInteger); 35 | @property (nonatomic, strong, readonly) NSArray *(^objectsAtIndexes)(NSIndexSet *); 36 | 37 | @end 38 | 39 | 40 | @interface NSMutableArray (XRCategory) 41 | + (instancetype)create:(void(^)(NSMutableArray *obj))block; 42 | + (instancetype)createWithArray:(NSArray *)array :(void(^)(NSMutableArray *obj))block; 43 | @property (nonatomic, strong, readonly) NSMutableArray *(^addObject)(id); 44 | @property (nonatomic, strong, readonly) NSMutableArray *(^insertObjAtIndex)(id, NSUInteger); 45 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeLastObj)(); 46 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjAtIndex)(NSUInteger); 47 | @property (nonatomic, strong, readonly) NSMutableArray *(^reaplaceObjAtIndexWithObj)(NSUInteger ,id); 48 | @property (nonatomic, strong, readonly) NSMutableArray *(^addObjsFromArray)(NSArray *); 49 | @property (nonatomic, strong, readonly) NSMutableArray *(^exchangeObjAtIndexWithIndex)(NSUInteger, NSUInteger); 50 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeAllObjs)(); 51 | 52 | /** 53 | * removeObject:(ObjectType)anObject inRange:(NSRange)range 54 | */ 55 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjInRange)(id, NSRange); 56 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObject)(id); 57 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjsInArray)(NSArray *); 58 | /** 59 | * removeObjectsInRange:(NSRange)range 60 | */ 61 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjsInRange)(NSRange); 62 | 63 | /** 64 | * replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray range:(NSRange)otherRange 65 | */ 66 | @property (nonatomic, strong, readonly) NSMutableArray *(^replaceObjsInRangeWithObjsFromArrayRange)(NSRange, NSArray *, NSRange); 67 | 68 | /** 69 | * replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray 70 | */ 71 | @property (nonatomic, strong, readonly) NSMutableArray *(^replaceObjsInRangeWithObjsFromArray)(NSRange, NSArray *); 72 | 73 | @property (nonatomic, strong, readonly) NSMutableArray *(^setArray)(NSArray *); 74 | 75 | /** 76 | * insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes 77 | */ 78 | @property (nonatomic, strong, readonly) NSMutableArray *(^insertObjsAtIndexes)(NSArray *, NSIndexSet *); 79 | 80 | /** 81 | * removeObjectsAtIndexes:(NSIndexSet *)indexes 82 | */ 83 | @property (nonatomic, strong, readonly) NSMutableArray *(^removeObjsAtIndexes)(NSIndexSet *); 84 | 85 | /** 86 | * replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects 87 | */ 88 | @property (nonatomic, strong, readonly) NSMutableArray *(^replaceObjsAtIndexesWithObjsFromArray)(NSIndexSet *, NSArray *); 89 | 90 | @property (nonatomic, strong, readonly) NSMutableArray *(^sortUsingComparator)(NSComparator); 91 | @end 92 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/NSArray+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+XRCategory.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "NSArray+XRCategory.h" 10 | 11 | @implementation NSArray (XRCategory) 12 | 13 | + (instancetype)createWithArray:(NSArray *)array :(void (^)(NSArray *))block{ 14 | NSArray *obj = [[NSArray alloc] initWithArray:array]; 15 | if (block) block(obj); 16 | return obj; 17 | } 18 | 19 | 20 | - (NSArray *(^)(id))arrayByAddObject { 21 | return ^(id obj) { 22 | return [self arrayByAddingObject:obj]; 23 | }; 24 | } 25 | 26 | - (NSArray *(^)(NSArray *))arrayByAddObjFromArray { 27 | return ^(NSArray *otherArray) { 28 | return [self arrayByAddingObjectsFromArray:otherArray]; 29 | }; 30 | } 31 | 32 | - (NSString *(^)(NSString *))componentsJoinByStr { 33 | return ^(NSString *str) { 34 | return [self componentsJoinedByString:str]; 35 | }; 36 | } 37 | 38 | 39 | - (NSUInteger (^)(id))indexOfObject { 40 | return ^(id obj) { 41 | return [self indexOfObject:obj]; 42 | }; 43 | } 44 | 45 | - (NSUInteger (^)(id, NSRange))indexOfObjInRange { 46 | return ^(id obj, NSRange range){ 47 | return [self indexOfObject:obj inRange:range]; 48 | }; 49 | } 50 | 51 | - (BOOL (^)(id))containsObject { 52 | return ^(id obj) { 53 | return [self containsObject:obj]; 54 | }; 55 | } 56 | 57 | - (BOOL (^)(NSArray *))isEqualToArray { 58 | return ^(NSArray *otherArray) { 59 | return [self isEqualToArray:otherArray]; 60 | }; 61 | } 62 | 63 | 64 | - (BOOL (^)(NSString *, BOOL))writeToFileAtomical { 65 | return ^(NSString *path, BOOL b) { 66 | return [self writeToFile:path atomically:b]; 67 | }; 68 | } 69 | 70 | - (BOOL (^)(NSURL *, BOOL))writeToURLAtomical { 71 | return ^(NSURL *url, BOOL b) { 72 | return [self writeToURL:url atomically:b]; 73 | }; 74 | } 75 | 76 | - (NSArray *(^)(SEL))makeObjPerformSel { 77 | return ^(SEL selector) { 78 | [self makeObjectsPerformSelector:selector]; 79 | return self; 80 | }; 81 | } 82 | 83 | 84 | - (NSArray *(^)(SEL, id))makeObjPerformSelWithObj { 85 | return ^(SEL selector, id obj) { 86 | [self makeObjectsPerformSelector:selector withObject:obj]; 87 | return self; 88 | }; 89 | } 90 | 91 | - (id (^)(NSUInteger))objectAtIndex { 92 | return ^(NSUInteger index) { 93 | return [self objectAtIndex:index]; 94 | }; 95 | } 96 | 97 | - (NSArray *(^)(NSIndexSet *))objectsAtIndexes { 98 | return ^(NSIndexSet *set) { 99 | return [self objectsAtIndexes:set]; 100 | }; 101 | } 102 | @end 103 | 104 | 105 | 106 | @implementation NSMutableArray (XRCategory) 107 | 108 | + (instancetype)create:(void (^)(NSMutableArray *))block{ 109 | NSMutableArray *obj = [[NSMutableArray alloc] init]; 110 | if (block) block(obj); 111 | return obj; 112 | } 113 | 114 | + (instancetype)createWithArray:(NSArray *)array :(void (^)(NSMutableArray *))block{ 115 | NSMutableArray *obj = [[NSMutableArray alloc] initWithArray:array]; 116 | if (block) block(obj); 117 | return obj; 118 | } 119 | 120 | - (NSMutableArray *(^)(id))addObject { 121 | return ^(id obj) { 122 | [self addObject:obj]; 123 | return self; 124 | }; 125 | } 126 | 127 | - (NSMutableArray *(^)(id, NSUInteger))insertObjAtIndex { 128 | return ^(id obj, NSUInteger index) { 129 | [self insertObject:obj atIndex:index]; 130 | return self; 131 | }; 132 | } 133 | 134 | - (NSMutableArray *(^)())removeLastObj { 135 | return ^() { 136 | [self removeLastObject]; 137 | return self; 138 | }; 139 | } 140 | 141 | - (NSMutableArray *(^)(NSUInteger))removeObjAtIndex { 142 | return ^(NSUInteger index) { 143 | [self removeObjectAtIndex:index]; 144 | return self; 145 | }; 146 | } 147 | 148 | - (NSMutableArray *(^)(NSUInteger, id))reaplaceObjAtIndexWithObj { 149 | return ^(NSUInteger index, id obj) { 150 | [self replaceObjectAtIndex:index withObject:obj]; 151 | return self; 152 | }; 153 | } 154 | 155 | - (NSMutableArray *(^)(NSArray *))addObjsFromArray { 156 | return ^(NSArray *array) { 157 | [self addObjectsFromArray:array]; 158 | return self; 159 | }; 160 | } 161 | 162 | - (NSMutableArray *(^)(NSUInteger, NSUInteger))exchangeObjAtIndexWithIndex { 163 | return ^(NSUInteger index1, NSUInteger index2) { 164 | [self exchangeObjectAtIndex:index1 withObjectAtIndex:index2]; 165 | return self; 166 | }; 167 | } 168 | 169 | - (NSMutableArray *(^)())removeAllObjs{ 170 | return ^(){ 171 | [self removeAllObjects]; 172 | return self; 173 | }; 174 | } 175 | 176 | - (NSMutableArray *(^)(id, NSRange))removeObjInRange { 177 | return ^(id obj, NSRange range) { 178 | [self removeObject:obj inRange:range]; 179 | return self; 180 | }; 181 | } 182 | 183 | - (NSMutableArray *(^)(id))removeObject { 184 | return ^(id obj) { 185 | [self removeObject:obj]; 186 | return self; 187 | }; 188 | } 189 | 190 | - (NSMutableArray *(^)(NSArray *))removeObjsInArray { 191 | return ^(NSArray *array) { 192 | [self removeObjectsInArray:array]; 193 | return self; 194 | }; 195 | } 196 | 197 | - (NSMutableArray *(^)(NSRange))removeObjsInRange { 198 | return ^(NSRange range){ 199 | [self removeObjectsInRange:range]; 200 | return self; 201 | }; 202 | } 203 | 204 | 205 | - (NSMutableArray *(^)(NSRange, NSArray *, NSRange))replaceObjsInRangeWithObjsFromArrayRange { 206 | return ^(NSRange range, NSArray *otherArray, NSRange otherRange) { 207 | [self replaceObjectsInRange:range withObjectsFromArray:otherArray range:otherRange]; 208 | return self; 209 | }; 210 | } 211 | 212 | 213 | - (NSMutableArray *(^)(NSRange, NSArray *))replaceObjsInRangeWithObjsFromArray { 214 | return ^(NSRange range, NSArray *otherArray) { 215 | [self replaceObjectsInRange:range withObjectsFromArray:otherArray]; 216 | return self; 217 | }; 218 | } 219 | 220 | - (NSMutableArray *(^)(NSArray *))setArray { 221 | return ^(NSArray *array) { 222 | [self setArray:array]; 223 | return self; 224 | }; 225 | } 226 | 227 | - (NSMutableArray *(^)(NSArray *, NSIndexSet *))insertObjsAtIndexes { 228 | return ^(NSArray *array, NSIndexSet *set) { 229 | [self insertObjects:array atIndexes:set]; 230 | return self; 231 | }; 232 | } 233 | 234 | - (NSMutableArray *(^)(NSIndexSet *))removeObjsAtIndexes { 235 | return ^(NSIndexSet *set) { 236 | [self removeObjectsAtIndexes:set]; 237 | return self; 238 | }; 239 | } 240 | 241 | - (NSMutableArray *(^)(NSIndexSet *, NSArray *))replaceObjsAtIndexesWithObjsFromArray { 242 | return ^(NSIndexSet *set, NSArray *array){ 243 | [self replaceObjectsAtIndexes:set withObjects:array]; 244 | return self; 245 | }; 246 | } 247 | 248 | 249 | - (NSMutableArray *(^)(NSComparator))sortUsingComparator { 250 | return ^(NSComparator comparator) { 251 | [self sortedArrayUsingComparator:comparator]; 252 | return self; 253 | }; 254 | } 255 | 256 | @end 257 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/NSDictionary+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDictionary (XRCategory) 12 | + (instancetype)createWithDicdionary:(NSDictionary *)dic :(void(^)(NSDictionary *obj))block; 13 | @property (nonatomic, strong, readonly) id (^objectForKey)(id); 14 | @property (nonatomic, strong, readonly) NSArray *(^allKeysForObject)(id); 15 | @property (nonatomic, strong, readonly) BOOL (^isEqualToDictionary)(NSDictionary *); 16 | /** 17 | * objectsForKeys:(NSArray *)keys notFoundMarker:(ObjectType)marker 18 | */ 19 | @property (nonatomic, strong, readonly) NSArray *(^objsForKeysNotFindMarker)(NSArray *, id); 20 | @property (nonatomic, strong, readonly) BOOL (^writeToFileAtomical)(NSString *, BOOL); 21 | @property (nonatomic, strong, readonly) BOOL (^writeToURLAtomical)(NSURL *,BOOL); 22 | 23 | /** 24 | * keysSortedByValueUsingSelector:(SEL)comparator 25 | */ 26 | @property (nonatomic, strong, readonly) NSArray *(^keysSortByValueUseSel)(SEL); 27 | @end 28 | 29 | @interface NSMutableDictionary (XRCategory) 30 | + (instancetype)create:(void(^)(NSMutableDictionary *obj))block; 31 | + (instancetype)createWithDicdionary:(NSDictionary *)dic :(void(^)(NSMutableDictionary *obj))block; 32 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^removeObjectForKey)(id); 33 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^setObjectForKey)(id, id); 34 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^removeAllObjs)(); 35 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^removeObjsForKeys)(NSArray *); 36 | @property (nonatomic, strong, readonly) NSMutableDictionary *(^setDictionary)(NSDictionary *); 37 | @end -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/NSDictionary+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+XRCategory.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+XRCategory.h" 10 | 11 | @implementation NSDictionary (XRCategory) 12 | 13 | + (instancetype)createWithDicdionary:(NSDictionary *)dic :(void (^)(NSDictionary *))block { 14 | NSDictionary *obj = [[NSDictionary alloc] initWithDictionary:dic]; 15 | if (block) block(obj); 16 | return obj; 17 | } 18 | 19 | - (id (^)(id))objectForKey { 20 | return ^(id key) { 21 | return [self objectForKey:key]; 22 | }; 23 | } 24 | 25 | - (NSArray *(^)(id))allKeysForObject { 26 | return ^(id obj) { 27 | return [self allKeysForObject:obj]; 28 | }; 29 | } 30 | 31 | - (BOOL (^)(NSDictionary *))isEqualToDictionary { 32 | return ^(NSDictionary *dic) { 33 | return [self isEqualToDictionary:dic]; 34 | }; 35 | } 36 | 37 | - (NSArray *(^)(NSArray *, id))objsForKeysNotFindMarker { 38 | return ^(NSArray *keys, id marker) { 39 | return [self objectsForKeys:keys notFoundMarker:marker]; 40 | }; 41 | } 42 | 43 | - (BOOL (^)(NSString *, BOOL))writeToFileAtomical { 44 | return ^(NSString *path, BOOL b) { 45 | return [self writeToFile:path atomically:b]; 46 | }; 47 | } 48 | 49 | - (BOOL (^)(NSURL *, BOOL))writeToURLAtomical { 50 | return ^(NSURL *url, BOOL b) { 51 | return [self writeToURL:url atomically:b]; 52 | }; 53 | } 54 | 55 | - (NSArray *(^)(SEL))keysSortByValueUseSel { 56 | return ^(SEL sel){ 57 | return [self keysSortedByValueUsingSelector:sel]; 58 | }; 59 | } 60 | 61 | @end 62 | 63 | 64 | @implementation NSMutableDictionary (XRCategory) 65 | + (instancetype)create:(void (^)(NSMutableDictionary *))block{ 66 | NSMutableDictionary *obj = [[NSMutableDictionary alloc] init]; 67 | if (block) block(obj); 68 | return obj; 69 | } 70 | 71 | + (instancetype)createWithDicdionary:(NSDictionary *)dic :(void (^)(NSMutableDictionary *))block { 72 | NSMutableDictionary *obj = [[NSMutableDictionary alloc] initWithDictionary:dic]; 73 | if (block) block(obj); 74 | return obj; 75 | } 76 | 77 | - (NSMutableDictionary *(^)(id))removeObjectForKey { 78 | return ^(id key) { 79 | [self removeObjectForKey:key]; 80 | return self; 81 | }; 82 | } 83 | 84 | - (NSMutableDictionary *(^)(id, id))setObjectForKey { 85 | return ^(id obj, id key) { 86 | [self setObject:obj forKey:key]; 87 | return self; 88 | }; 89 | } 90 | 91 | - (NSMutableDictionary *(^)())removeAllObjs { 92 | return ^(){ 93 | [self removeAllObjects]; 94 | return self; 95 | }; 96 | } 97 | 98 | - (NSMutableDictionary *(^)(NSArray *))removeObjsForKeys { 99 | return ^(NSArray *keys) { 100 | [self removeObjectsForKeys:keys]; 101 | return self; 102 | }; 103 | } 104 | 105 | - (NSMutableDictionary *(^)(NSDictionary *))setDictionary { 106 | return ^(NSDictionary *dic) { 107 | [self setDictionary:dic]; 108 | return self; 109 | }; 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/NSObject+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface NSObject (XRCategory) 11 | + (instancetype)create:(void(^)(id obj))block; 12 | 13 | 14 | //- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2; 15 | //@property (nonatomic, strong, readonly) id(^performSelWith2Obj)(SEL, id, id); 16 | 17 | //- (void)performSelector:(SEL)aSelector withObject:(nullable id)anArgument afterDelay:(NSTimeInterval)delay; 18 | @property (nonatomic, strong, readonly) void(^performSelAfterDelay)(SEL, id, NSTimeInterval); 19 | 20 | //- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(nullable id)arg waitUntilDone:(BOOL)wait; 21 | @property (nonatomic, strong, readonly) void(^performSelOnMainThread)(SEL, id, BOOL); 22 | 23 | //- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(nullable id)arg waitUntilDone:(BOOL)wait 24 | @property (nonatomic, strong, readonly) void(^performSelOnThread)(SEL, NSThread *, id, BOOL); 25 | 26 | //- (void)performSelectorInBackground:(SEL)aSelector withObject:(nullable id)arg 27 | @property (nonatomic, strong, readonly) void(^performSelInBackground)(SEL, id); 28 | 29 | //- (BOOL)isKindOfClass:(Class)aClass; 30 | @property (nonatomic, strong, readonly) BOOL(^isKindOfClass)(Class); 31 | 32 | //- (BOOL)isMemberOfClass:(Class)aClass; 33 | @property (nonatomic, strong, readonly) BOOL(^isMemberOfClass)(Class); 34 | 35 | //- (BOOL)conformsToProtocol:(Protocol *)aProtocol; 36 | @property (nonatomic, strong, readonly) BOOL(^conformsToProtocol)(Protocol *); 37 | 38 | //- (BOOL)respondsToSelector:(SEL)aSelector; 39 | @property (nonatomic, strong, readonly) BOOL(^respondsToSelector)(SEL); 40 | 41 | //- (BOOL)isEqual:(id)object; 42 | @property (nonatomic, strong, readonly) BOOL(^isEqual)(id); 43 | 44 | @property (nonatomic, strong, readonly) id (^valueForKey)(NSString *); 45 | @property (nonatomic, strong, readonly) void(^setValueForKey)(id, NSString *); 46 | @property (nonatomic, strong, readonly) id (^valueForKeyPath)(NSString *); 47 | @property (nonatomic, strong, readonly) void(^setValueForKeyPath)(id, NSString *); 48 | @property (nonatomic, strong, readonly) void(^setValuesForKeysWithDic)(NSDictionary *); 49 | @property (nonatomic, strong, readonly) NSDictionary *(^dicWithValuesForKeys)(NSArray *); 50 | 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/NSObject+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "NSObject+XRCategory.h" 9 | 10 | @implementation NSObject (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(id))block{ 13 | id obj = [[self alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | //- (id (^)(SEL, id, id))performSelWith2Obj { 19 | // return ^(SEL selector, id obj1, id obj2) { 20 | // return [self performSelector:selector withObject:obj1 withObject:obj2]; 21 | // }; 22 | //} 23 | 24 | 25 | - (void (^)(SEL, id, NSTimeInterval))performSelAfterDelay { 26 | return ^(SEL selector, id obj, NSTimeInterval delay){ 27 | [self performSelector:selector withObject:obj afterDelay:delay]; 28 | }; 29 | } 30 | 31 | 32 | - (void(^)(SEL, id, BOOL))performSelOnMainThread { 33 | return ^(SEL selector, id obj, BOOL b) { 34 | [self performSelectorOnMainThread:selector withObject:obj waitUntilDone:b]; 35 | }; 36 | } 37 | 38 | - (void(^)(SEL, NSThread *, id, BOOL))performSelOnThread { 39 | return ^(SEL selector, NSThread * thread, id obj, BOOL b) { 40 | return [self performSelector:selector onThread:thread withObject:obj waitUntilDone:b]; 41 | }; 42 | } 43 | 44 | - (void(^)(SEL , id))performSelInBackground { 45 | return ^(SEL selector, id obj) { 46 | return [self performSelectorInBackground:selector withObject:obj]; 47 | }; 48 | } 49 | 50 | 51 | - (BOOL (^)(__unsafe_unretained Class))isKindOfClass { 52 | return ^(Class class){ 53 | return [self isKindOfClass:class]; 54 | }; 55 | } 56 | 57 | - (BOOL (^)(__unsafe_unretained Class))isMemberOfClass { 58 | return ^(Class class){ 59 | return [self isMemberOfClass:class]; 60 | }; 61 | } 62 | 63 | - (BOOL (^)(Protocol *))conformsToProtocol { 64 | return ^(Protocol *protocol){ 65 | return [self conformsToProtocol:protocol]; 66 | }; 67 | } 68 | 69 | - (BOOL (^)(SEL))respondsToSelector { 70 | return ^(SEL selector){ 71 | return [self respondsToSelector:selector]; 72 | }; 73 | } 74 | 75 | - (BOOL (^)(id))isEqual { 76 | return ^(id obj){ 77 | return [self isKindOfClass:obj]; 78 | }; 79 | } 80 | 81 | - (id (^)(NSString *))valueForKey{ 82 | return ^(NSString *key) { 83 | return [self valueForKey:key]; 84 | }; 85 | } 86 | 87 | - (id (^)(NSString *))valueForKeyPath{ 88 | return ^(NSString *keyPath) { 89 | return [self valueForKeyPath:keyPath]; 90 | }; 91 | } 92 | 93 | - (void (^)(id, NSString *))setValueForKey { 94 | return ^(id value, NSString * key) { 95 | [self setValue:value forKey:key]; 96 | }; 97 | } 98 | 99 | - (void (^)(id, NSString *))setValueForKeyPath { 100 | return ^(id value, NSString * keyPath) { 101 | [self setValue:value forKey:keyPath]; 102 | }; 103 | } 104 | 105 | - (void (^)(NSDictionary *))setValuesForKeysWithDic { 106 | return ^(NSDictionary *dic) { 107 | [self setValuesForKeysWithDictionary:dic]; 108 | }; 109 | } 110 | 111 | - (NSDictionary *(^)(NSArray *))dicWithValuesForKeys { 112 | return ^(NSArray *keys) { 113 | return [self dictionaryWithValuesForKeys:keys]; 114 | }; 115 | } 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/NSString+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (XRCategory) 12 | 13 | + (instancetype)createWithString:(NSString *)str :(void(^)(NSString *obj))block; 14 | 15 | @property (nonatomic, strong, readonly) unichar (^charAtIndex)(NSUInteger); 16 | @property (nonatomic, strong, readonly) NSString *(^subStrFromIndex)(NSUInteger); 17 | @property (nonatomic, strong, readonly) NSString *(^subStrToIndex)(NSUInteger); 18 | @property (nonatomic, strong, readonly) NSString *(^subStrWithRange)(NSRange); 19 | @property (nonatomic, strong, readonly) BOOL (^isEqualToString)(NSString *); 20 | @property (nonatomic, strong, readonly) NSComparisonResult (^compare)(NSString *); 21 | @property (nonatomic, strong, readonly) NSRange (^rangeOfString)(NSString *); 22 | @property (nonatomic, strong, readonly) BOOL (^hasPrefix)(NSString *); 23 | @property (nonatomic, strong, readonly) BOOL (^hasSuffix)(NSString *); 24 | @property (nonatomic, strong, readonly) BOOL (^containsString)(NSString *); 25 | @property (nonatomic, strong, readonly) NSString *(^stringByAppendStr)(NSString *); 26 | @property (nonatomic, strong, readonly) NSData *(^dataUsingEncoding)(NSStringEncoding); 27 | @property (nonatomic, strong, readonly) const char *(^cStringUsingEncoding)(NSStringEncoding); 28 | 29 | 30 | /** 31 | * componentsSeparatedByString:(NSString *)separator 32 | */ 33 | @property (nonatomic, strong, readonly) NSArray *(^componentSeparatByStr)(NSString *); 34 | 35 | /** 36 | * stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement 37 | */ 38 | @property (nonatomic, strong, readonly) NSString *(^stringByReplaceStringWithStr)(NSString *, NSString *); 39 | 40 | /** 41 | * stringByReplacingCharactersInRange:(NSRange)range withString:(NSString *)replacement 42 | */ 43 | @property (nonatomic, strong, readonly) NSString *(^stringByReplaceCharInRangeWithStr)(NSRange, NSString *); 44 | 45 | 46 | /** 47 | * writeToURL:(NSURL *)url atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error 48 | */ 49 | @property (nonatomic, strong, readonly) BOOL (^writeToFileAtomical)(NSString *, BOOL, NSStringEncoding, NSError **); 50 | 51 | /** 52 | * writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error 53 | */ 54 | @property (nonatomic, strong, readonly) BOOL (^writeToURLAtomical)(NSURL *, BOOL, NSStringEncoding, NSError **); 55 | 56 | 57 | @end 58 | 59 | 60 | @interface NSMutableString (XRCategory) 61 | 62 | + (instancetype)create:(void(^)(NSMutableString *obj))block; 63 | + (instancetype)createWithString:(NSString *)str :(void(^)(NSMutableString *obj))block; 64 | 65 | @property (nonatomic, strong, readonly) NSMutableString *(^replaceCharInRange)(NSRange, NSString *); 66 | @property (nonatomic, strong, readonly) NSMutableString *(^insertStrAtIndex)(NSString *, NSUInteger); 67 | @property (nonatomic, strong, readonly) NSMutableString *(^deleteCharInRange)(NSRange); 68 | @property (nonatomic, strong, readonly) NSMutableString *(^appendStr)(NSString *); 69 | @property (nonatomic, strong, readonly) NSMutableString *(^setString)(NSString *); 70 | @end 71 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/NSString+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+XRCategory.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "NSString+XRCategory.h" 10 | 11 | @implementation NSString (XRCategory) 12 | 13 | 14 | + (instancetype)createWithString:(NSString *)str :(void (^)(NSString *))block{ 15 | NSString *obj = [[NSString alloc] initWithString:str]; 16 | if (block) block(obj); 17 | return obj; 18 | } 19 | 20 | - (unichar (^)(NSUInteger))charAtIndex { 21 | return ^(NSUInteger index){ 22 | return [self characterAtIndex:index]; 23 | }; 24 | } 25 | 26 | - (NSString *(^)(NSUInteger))subStrFromIndex { 27 | return ^(NSUInteger index){ 28 | return [self substringFromIndex:index]; 29 | }; 30 | } 31 | 32 | - (NSString *(^)(NSUInteger))subStrToIndex { 33 | return ^(NSUInteger index){ 34 | return [self substringToIndex:index]; 35 | }; 36 | } 37 | 38 | - (NSString *(^)(NSRange))subStrWithRange { 39 | return ^(NSRange range){ 40 | return [self substringWithRange:range]; 41 | }; 42 | } 43 | 44 | - (BOOL (^)(NSString *))isEqualToString{ 45 | return ^(NSString *str){ 46 | return [self isEqualToString:str]; 47 | }; 48 | } 49 | 50 | - (NSComparisonResult (^)(NSString *))compare{ 51 | return ^(NSString *str){ 52 | return [self compare:str]; 53 | }; 54 | } 55 | 56 | - (NSRange (^)(NSString *))rangeOfString { 57 | return ^(NSString *str){ 58 | return [self rangeOfString:str]; 59 | }; 60 | } 61 | 62 | - (BOOL (^)(NSString *))hasPrefix{ 63 | return ^(NSString *str){ 64 | return [self hasPrefix:str]; 65 | }; 66 | } 67 | 68 | - (BOOL (^)(NSString *))hasSuffix{ 69 | return ^(NSString *str){ 70 | return [self hasSuffix:str]; 71 | }; 72 | } 73 | 74 | - (BOOL (^)(NSString *))containsString{ 75 | return ^(NSString *str){ 76 | return [self containsString:str]; 77 | }; 78 | } 79 | 80 | - (NSString *(^)(NSString *))stringByAppendStr { 81 | return ^(NSString *str){ 82 | return [self stringByAppendingString:str]; 83 | }; 84 | } 85 | 86 | - (NSData *(^)(NSStringEncoding))dataUsingEncoding { 87 | return ^(NSStringEncoding encoding) { 88 | return [self dataUsingEncoding:encoding]; 89 | }; 90 | } 91 | 92 | - (const char *(^)(NSStringEncoding))cStringUsingEncoding { 93 | return ^(NSStringEncoding encoding) { 94 | return [self cStringUsingEncoding:encoding]; 95 | }; 96 | } 97 | 98 | - (NSArray *(^)(NSString *))componentSeparatByStr { 99 | return ^(NSString *str) { 100 | return [self componentsSeparatedByString:str]; 101 | }; 102 | } 103 | 104 | - (NSString *(^)(NSString *, NSString *))stringByReplaceStringWithStr { 105 | return ^(NSString *target, NSString *replacement) { 106 | return [self stringByReplacingOccurrencesOfString:target withString:replacement]; 107 | }; 108 | } 109 | 110 | 111 | - (NSString *(^)(NSRange, NSString *))stringByReplaceCharInRangeWithStr { 112 | return ^(NSRange range, NSString *replacement) { 113 | return [self stringByReplacingCharactersInRange:range withString:replacement]; 114 | }; 115 | } 116 | 117 | 118 | - (BOOL (^)(NSString *, BOOL, NSStringEncoding, NSError **))writeToFileAtomical { 119 | return ^(NSString *path, BOOL b, NSStringEncoding encoding, NSError **error){ 120 | return [self writeToFile:path atomically:b encoding:encoding error:error]; 121 | }; 122 | } 123 | 124 | 125 | - (BOOL (^)(NSURL *, BOOL, NSStringEncoding, NSError **)) writeToURLAtomical{ 126 | return ^(NSURL *url, BOOL b, NSStringEncoding encoding, NSError **error){ 127 | return [self writeToURL:url atomically:b encoding:encoding error:error]; 128 | }; 129 | } 130 | 131 | @end 132 | 133 | 134 | @implementation NSMutableString (XRCategory) 135 | 136 | 137 | + (instancetype)create:(void (^)(NSMutableString *))block{ 138 | NSMutableString *obj = [[NSMutableString alloc] init]; 139 | if (block) block(obj); 140 | return obj; 141 | } 142 | 143 | +(instancetype)createWithString:(NSString *)str :(void (^)(NSMutableString *))block { 144 | NSMutableString *obj = [[NSMutableString alloc] initWithString:str]; 145 | if (block) block(obj); 146 | return obj; 147 | } 148 | 149 | - (NSMutableString *(^)(NSRange, NSString *))replaceCharInRange { 150 | return ^(NSRange range, NSString *str) { 151 | [self replaceCharactersInRange:range withString:str]; 152 | return self; 153 | }; 154 | } 155 | 156 | - (NSMutableString *(^)(NSString *, NSUInteger))insertStrAtIndex { 157 | return ^(NSString *str, NSUInteger index) { 158 | [self insertString:str atIndex:index]; 159 | return self; 160 | }; 161 | } 162 | 163 | - (NSMutableString *(^)(NSRange))deleteCharInRange { 164 | return ^(NSRange range) { 165 | [self deleteCharactersInRange:range]; 166 | return self; 167 | }; 168 | } 169 | 170 | - (NSMutableString *(^)(NSString *))appendStr { 171 | return ^(NSString *str) { 172 | [self appendString:str]; 173 | return self; 174 | }; 175 | } 176 | 177 | - (NSMutableString *(^)(NSString *))setString { 178 | return ^( NSString *str) { 179 | [self setString:str]; 180 | return self; 181 | }; 182 | } 183 | 184 | 185 | @end 186 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIButton+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIButton (XRCategory) 11 | + (instancetype)create:(void(^)(UIButton *obj))block; 12 | 13 | //contentEdgeInsets 14 | @property (nonatomic, strong, readonly) UIButton *(^contentEdge)(UIEdgeInsets); 15 | @property (nonatomic, strong, readonly) UIButton *(^contentEdgeEle)(CGFloat, CGFloat, CGFloat, CGFloat); 16 | 17 | //imageEdgeInsets 18 | @property (nonatomic, strong, readonly) UIButton *(^imageEdge)(UIEdgeInsets); 19 | @property (nonatomic, strong, readonly) UIButton *(^imageEdgeEle)(CGFloat, CGFloat, CGFloat, CGFloat); 20 | 21 | //titleEdgeInsets 22 | @property (nonatomic, strong, readonly) UIButton *(^titleEdge)(UIEdgeInsets); 23 | @property (nonatomic, strong, readonly) UIButton *(^titleEdgeEle)(CGFloat, CGFloat, CGFloat, CGFloat); 24 | 25 | @property (nonatomic, strong, readonly) UIButton *(^adjustImgWhenHighlight)(BOOL); 26 | @property (nonatomic, strong, readonly) UIButton *(^adjustImgWhenDisable)(BOOL); 27 | @property (nonatomic, strong, readonly) UIButton *(^showTouchWhenHighlight)(BOOL); 28 | 29 | @property (nonatomic, strong, readonly) UIButton *(^setTitleForState)(NSString *, UIControlState); 30 | @property (nonatomic, strong, readonly) UIButton *(^setTitleColorForState)(UIColor *, UIControlState); 31 | @property (nonatomic, strong, readonly) UIButton *(^setShadowColorForState)(UIColor *, UIControlState); 32 | @property (nonatomic, strong, readonly) UIButton *(^setImageForState)(UIImage *, UIControlState); 33 | @property (nonatomic, strong, readonly) UIButton *(^setBgImageForState)(UIImage *, UIControlState); 34 | @property (nonatomic, strong, readonly) UIButton *(^setAttrituteTitleForState)(NSAttributedString *, UIControlState); 35 | 36 | 37 | /** 38 | * 以下属性是用来取值的,返回值不为方法调用者 39 | */ 40 | @property (nonatomic, strong, readonly) NSString *(^titleForState)(UIControlState); 41 | @property (nonatomic, strong, readonly) NSAttributedString *(^attributeTitleForState)(UIControlState); 42 | @property (nonatomic, strong, readonly) UIColor *(^titleColorForState)(UIControlState); 43 | @property (nonatomic, strong, readonly) UIColor *(^shadowColorForState)(UIControlState); 44 | @property (nonatomic, strong, readonly) UIImage *(^imageForState)(UIControlState); 45 | @property (nonatomic, strong, readonly) UIImage *(^bgImageForState)(UIControlState); 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIButton+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIButton+XRCategory.h" 9 | 10 | @implementation UIButton (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UIButton *))block{ 13 | UIButton *obj = [[UIButton alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | - (UIButton *(^)(UIEdgeInsets))contentEdge { 19 | return ^(UIEdgeInsets edge){ 20 | self.contentEdgeInsets = edge; 21 | return self; 22 | }; 23 | } 24 | 25 | - (UIButton *(^)(CGFloat, CGFloat, CGFloat, CGFloat))contentEdgeEle { 26 | return ^(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right){ 27 | self.contentEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right); 28 | return self; 29 | }; 30 | } 31 | 32 | - (UIButton *(^)(UIEdgeInsets))titleEdge { 33 | return ^(UIEdgeInsets edge){ 34 | self.titleEdgeInsets = edge; 35 | return self; 36 | }; 37 | } 38 | 39 | - (UIButton *(^)(CGFloat, CGFloat, CGFloat, CGFloat))titleEdgeEle { 40 | return ^(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right){ 41 | self.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right); 42 | return self; 43 | }; 44 | } 45 | 46 | - (UIButton *(^)(UIEdgeInsets))imageEdge { 47 | return ^(UIEdgeInsets edge){ 48 | self.imageEdgeInsets = edge; 49 | return self; 50 | }; 51 | } 52 | 53 | - (UIButton *(^)(CGFloat, CGFloat, CGFloat, CGFloat))imageEdgeEle { 54 | return ^(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right){ 55 | self.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right); 56 | return self; 57 | }; 58 | } 59 | 60 | - (UIButton *(^)(BOOL))adjustImgWhenHighlight { 61 | return ^(BOOL b) { 62 | self.adjustsImageWhenHighlighted = b; 63 | return self; 64 | }; 65 | } 66 | 67 | - (UIButton *(^)(BOOL))adjustImgWhenDisable { 68 | return ^(BOOL b) { 69 | self.adjustsImageWhenDisabled = b; 70 | return self; 71 | }; 72 | } 73 | 74 | - (UIButton *(^)(BOOL))showTouchWhenHighlight { 75 | return ^(BOOL b) { 76 | self.showsTouchWhenHighlighted = b; 77 | return self; 78 | }; 79 | } 80 | 81 | - (UIButton *(^)(NSString *, UIControlState))setTitleForState { 82 | return ^(NSString *title, UIControlState state) { 83 | [self setTitle:title forState:state]; 84 | return self; 85 | }; 86 | } 87 | 88 | - (UIButton *(^)(NSAttributedString *, UIControlState))setAttrituteTitleForState { 89 | return ^(NSAttributedString *title, UIControlState state) { 90 | [self setAttributedTitle:title forState:state]; 91 | return self; 92 | }; 93 | } 94 | 95 | - (UIButton *(^)(UIColor *, UIControlState))setTitleColorForState { 96 | return ^(UIColor *color, UIControlState state) { 97 | [self setTitleColor:color forState:state]; 98 | return self; 99 | }; 100 | } 101 | 102 | - (UIButton *(^)(UIColor *, UIControlState))setShadowColorForState { 103 | return ^(UIColor *color, UIControlState state) { 104 | [self setTitleShadowColor:color forState:state]; 105 | return self; 106 | }; 107 | } 108 | 109 | 110 | - (UIButton *(^)(UIImage *, UIControlState))setImageForState { 111 | return ^(UIImage *image, UIControlState state) { 112 | [self setImage:image forState:state]; 113 | return self; 114 | }; 115 | } 116 | 117 | - (UIButton *(^)(UIImage *, UIControlState))setBgImageForState { 118 | return ^(UIImage *image, UIControlState state) { 119 | [self setBackgroundImage:image forState:state]; 120 | return self; 121 | }; 122 | } 123 | 124 | - (NSString *(^)(UIControlState))titleForState { 125 | return ^(UIControlState state){ 126 | return [self titleForState:state]; 127 | }; 128 | } 129 | 130 | - (NSAttributedString *(^)(UIControlState))attributeTitleForState { 131 | return ^(UIControlState state){ 132 | return [self attributedTitleForState:state]; 133 | }; 134 | } 135 | 136 | - (UIColor *(^)(UIControlState))titleColorForState { 137 | return ^(UIControlState state){ 138 | return [self titleColorForState:state]; 139 | }; 140 | } 141 | 142 | - (UIColor *(^)(UIControlState))shadowColorForState { 143 | return ^(UIControlState state){ 144 | return [self titleShadowColorForState:state]; 145 | }; 146 | } 147 | 148 | - (UIImage *(^)(UIControlState))imageForState { 149 | return ^(UIControlState state){ 150 | return [self imageForState:state]; 151 | }; 152 | } 153 | 154 | - (UIImage *(^)(UIControlState))bgImageForState { 155 | return ^(UIControlState state){ 156 | return [self backgroundImageForState:state]; 157 | }; 158 | } 159 | 160 | 161 | @end 162 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIControl+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIControl+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIControl (XRCategory) 11 | //enabled 12 | @property (nonatomic, strong, readonly) UIControl *(^enable)(BOOL); 13 | 14 | //selected 15 | @property (nonatomic, strong, readonly) UIControl *(^select)(BOOL); 16 | 17 | //highlighted 18 | @property (nonatomic, strong, readonly) UIControl *(^highlight)(BOOL); 19 | 20 | //contentVerticalAlignment 21 | @property (nonatomic, strong, readonly) UIControl *(^verticalAlignment)(UIControlContentVerticalAlignment); 22 | 23 | //contentHorizontalAlignment 24 | @property (nonatomic, strong, readonly) UIControl *(^horizontalAlignment)(UIControlContentHorizontalAlignment); 25 | 26 | @property (nonatomic, strong, readonly) UIControl *(^addTarget)(id, SEL, UIControlEvents); 27 | @property (nonatomic, strong, readonly) UIControl *(^removeTarget)(id, SEL, UIControlEvents); 28 | @end 29 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIControl+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIControl+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIControl+XRCategory.h" 9 | 10 | @implementation UIControl (XRCategory) 11 | 12 | - (UIControl *(^)(BOOL))enable { 13 | return ^(BOOL b){ 14 | self.enabled = b; 15 | return self; 16 | }; 17 | } 18 | 19 | - (UIControl *(^)(BOOL))select { 20 | return ^(BOOL b){ 21 | self.selected = b; 22 | return self; 23 | }; 24 | } 25 | 26 | - (UIControl *(^)(BOOL))highlight { 27 | return ^(BOOL b){ 28 | self.highlighted = b; 29 | return self; 30 | }; 31 | } 32 | 33 | - (UIControl *(^)(UIControlContentVerticalAlignment))verticalAlignment { 34 | return ^(UIControlContentVerticalAlignment alignment){ 35 | self.contentVerticalAlignment = alignment; 36 | return self; 37 | }; 38 | } 39 | 40 | - (UIControl *(^)(UIControlContentHorizontalAlignment))horizontalAlignment { 41 | return ^(UIControlContentHorizontalAlignment alignment){ 42 | self.contentHorizontalAlignment = alignment; 43 | return self; 44 | }; 45 | } 46 | 47 | - (UIControl *(^)(id, SEL, UIControlEvents))addTarget { 48 | return ^(id target, SEL action, UIControlEvents event){ 49 | [self addTarget:target action:action forControlEvents:event]; 50 | return self; 51 | }; 52 | } 53 | 54 | - (UIControl *(^)(id, SEL, UIControlEvents))removeTarget { 55 | return ^(id target, SEL action, UIControlEvents event){ 56 | [self removeTarget:target action:action forControlEvents:event]; 57 | return self; 58 | }; 59 | } 60 | @end 61 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIImageView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIImageView (XRCategory) 11 | 12 | + (instancetype)create:(void(^)(UIImageView *obj))block; 13 | 14 | 15 | //image 16 | @property (nonatomic, strong, readonly) UIImageView *(^Image)(UIImage *); 17 | //highlightedImage 18 | @property (nonatomic, strong, readonly) UIImageView *(^highlightImg)(UIImage *); 19 | 20 | @property (nonatomic, strong, readonly) UIImageView *(^highlight)(BOOL); 21 | 22 | //animationImages 23 | @property (nonatomic, strong, readonly) UIImageView *(^animationImgs)(NSArray *); 24 | @property (nonatomic, strong, readonly) UIImageView *(^highlightAnimaImgs)(NSArray *); 25 | 26 | //animationDuration 27 | @property (nonatomic, strong, readonly) UIImageView *(^animaDuration)(NSTimeInterval); 28 | //animationRepeatCount 29 | @property (nonatomic, strong, readonly) UIImageView *(^animaRepeatCount)(NSInteger); 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIImageView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+XRCategory.m 3 | 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIImageView+XRCategory.h" 9 | 10 | @implementation UIImageView (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UIImageView *))block{ 13 | UIImageView *obj = [[UIImageView alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | - (UIImageView *(^)(UIImage *))Image { 19 | return ^(UIImage *image){ 20 | self.image = image; 21 | return self; 22 | }; 23 | } 24 | 25 | - (UIImageView *(^)(UIImage *))highlightImg { 26 | return ^(UIImage *image){ 27 | self.highlightedImage = image; 28 | return self; 29 | }; 30 | } 31 | 32 | - (UIImageView *(^)(BOOL))highlight { 33 | return ^(BOOL b){ 34 | self.highlighted = b; 35 | return self; 36 | }; 37 | } 38 | 39 | - (UIImageView *(^)(NSArray *))animationImgs { 40 | return ^(NSArray *images){ 41 | self.animationImages = images; 42 | return self; 43 | }; 44 | } 45 | 46 | - (UIImageView *(^)(NSArray *))highlightAnimaImgs { 47 | return ^(NSArray *images){ 48 | self.highlightedAnimationImages = images; 49 | return self; 50 | }; 51 | } 52 | 53 | - (UIImageView *(^)(NSTimeInterval))animaDuration { 54 | return ^(NSTimeInterval time){ 55 | self.animationDuration = time; 56 | return self; 57 | }; 58 | } 59 | 60 | - (UIImageView *(^)(NSInteger))animaRepeatCount { 61 | return ^(NSInteger count){ 62 | self.animationRepeatCount = count; 63 | return self; 64 | }; 65 | } 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UILabel+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UILabel (XRCategory) 11 | + (instancetype)create:(void(^)(UILabel *obj))block; 12 | 13 | //text 14 | @property (nonatomic, strong, readonly) UILabel *(^Text)(NSString *); 15 | 16 | @property (nonatomic, strong, readonly) UILabel *(^attributeText)(NSAttributedString *); 17 | @property (nonatomic, strong, readonly) UILabel *(^TextAlignment)(NSTextAlignment); 18 | @property (nonatomic, strong, readonly) UILabel *(^TextColor)(UIColor *); 19 | @property (nonatomic, strong, readonly) UILabel *(^textColorRGB)(CGFloat, CGFloat, CGFloat, CGFloat); 20 | @property (nonatomic, strong, readonly) UILabel *(^highlightTextColor)(UIColor *); 21 | @property (nonatomic, strong, readonly) UILabel *(^highlight)(BOOL); 22 | @property (nonatomic, strong, readonly) UILabel *(^enable)(BOOL); 23 | 24 | //font 25 | @property (nonatomic, strong, readonly) UILabel *(^Font)(UIFont *); 26 | @property (nonatomic, strong, readonly) UILabel *(^fontSize)(NSInteger); 27 | @property (nonatomic, strong, readonly) UILabel *(^ShadowColor)(UIColor *); 28 | @property (nonatomic, strong, readonly) UILabel *(^ShadowOffset)(CGSize); 29 | @property (nonatomic, strong, readonly) UILabel *(^LineBreakMode)(NSLineBreakMode); 30 | @property (nonatomic, strong, readonly) UILabel *(^numberOfLine)(NSInteger); 31 | 32 | @property (nonatomic, strong, readonly) UILabel *(^adjustFontToFit)(BOOL); 33 | @property (nonatomic, strong, readonly) UILabel *(^baselineAdjust)(UIBaselineAdjustment); 34 | 35 | //drawTextInRect 36 | @property (nonatomic, strong, readonly) UILabel *(^drawText)(CGRect); 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UILabel+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UILabel+XRCategory.h" 9 | 10 | @implementation UILabel (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UILabel *))block{ 13 | UILabel *obj = [[UILabel alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | - (UILabel *(^)(NSString *))Text { 19 | return ^(NSString *text){ 20 | self.text = text; 21 | return self; 22 | }; 23 | } 24 | 25 | - (UILabel *(^)(NSAttributedString *))attributeText { 26 | return ^(NSAttributedString *attributedText){ 27 | self.attributedText = attributedText; 28 | return self; 29 | }; 30 | } 31 | 32 | - (UILabel *(^)(NSTextAlignment))TextAlignment { 33 | return ^(NSTextAlignment alignment){ 34 | self.textAlignment = alignment; 35 | return self; 36 | }; 37 | } 38 | 39 | - (UILabel *(^)(UIColor *))TextColor { 40 | return ^(UIColor *color){ 41 | self.textColor = color; 42 | return self; 43 | }; 44 | } 45 | 46 | - (UILabel *(^)(CGFloat, CGFloat, CGFloat, CGFloat))textColorRGB { 47 | return ^(CGFloat r, CGFloat g, CGFloat b, CGFloat a){ 48 | self.textColor = [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:g / 255.0 alpha:a]; 49 | return self; 50 | }; 51 | } 52 | 53 | - (UILabel *(^)(UIColor *))highlightTextColor { 54 | return ^(UIColor *color){ 55 | self.highlightedTextColor = color; 56 | return self; 57 | }; 58 | } 59 | 60 | - (UILabel *(^)(BOOL))highlight { 61 | return ^(BOOL b){ 62 | self.highlighted = b; 63 | return self; 64 | }; 65 | } 66 | 67 | - (UILabel *(^)(BOOL))enable { 68 | return ^(BOOL b){ 69 | self.enabled = b; 70 | return self; 71 | }; 72 | } 73 | 74 | - (UILabel *(^)(UIFont *))Font { 75 | return ^(UIFont *font){ 76 | self.font = font; 77 | return self; 78 | }; 79 | } 80 | 81 | - (UILabel *(^)(NSInteger))fontSize { 82 | return ^(NSInteger size){ 83 | self.font = [UIFont systemFontOfSize:size]; 84 | return self; 85 | }; 86 | } 87 | 88 | - (UILabel *(^)(UIColor *))ShadowColor { 89 | return ^(UIColor *color){ 90 | self.shadowColor = color; 91 | return self; 92 | }; 93 | } 94 | 95 | - (UILabel *(^)(CGSize))ShadowOffset { 96 | return ^(CGSize size){ 97 | self.shadowOffset = size; 98 | return self; 99 | }; 100 | } 101 | 102 | - (UILabel *(^)(NSLineBreakMode))LineBreakMode { 103 | return ^(NSLineBreakMode mode){ 104 | self.lineBreakMode = mode; 105 | return self; 106 | }; 107 | } 108 | 109 | - (UILabel *(^)(NSInteger))numberOfLine { 110 | return ^(NSInteger num){ 111 | self.numberOfLines = num; 112 | return self; 113 | }; 114 | } 115 | 116 | - (UILabel *(^)(BOOL))adjustFontToFit { 117 | return ^(BOOL b){ 118 | self.adjustsFontSizeToFitWidth = b; 119 | return self; 120 | }; 121 | } 122 | 123 | - (UILabel *(^)(UIBaselineAdjustment))baselineAdjust { 124 | return ^(UIBaselineAdjustment adjustment){ 125 | self.baselineAdjustment = adjustment; 126 | return self; 127 | }; 128 | } 129 | 130 | - (UILabel *(^)(CGRect))drawText{ 131 | return ^(CGRect rect){ 132 | [self drawTextInRect:rect]; 133 | return self; 134 | }; 135 | } 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIScrollView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIScrollView (XRCategory) 11 | + (instancetype)create:(void(^)(UIScrollView *obj))block; 12 | 13 | 14 | @property (nonatomic, strong, readonly) UIScrollView *(^ContentOffset)(CGPoint); 15 | @property (nonatomic, strong, readonly) UIScrollView *(^ContentSize)(CGSize); 16 | @property (nonatomic, strong, readonly) UIScrollView *(^ContentInset)(UIEdgeInsets); 17 | @property (nonatomic, strong, readonly) UIScrollView *(^Delegate)(id); 18 | @property (nonatomic, strong, readonly) UIScrollView *(^bounce)(BOOL); 19 | 20 | //alwaysBounceVertical 21 | @property (nonatomic, strong, readonly) UIScrollView *(^alwaysBounceV)(BOOL); 22 | //alwaysBounceHorizontal 23 | @property (nonatomic, strong, readonly) UIScrollView *(^alwaysBounceH)(BOOL); 24 | @property (nonatomic, strong, readonly) UIScrollView *(^pagingEnable)(BOOL); 25 | @property (nonatomic, strong, readonly) UIScrollView *(^scrollEnable)(BOOL); 26 | 27 | //showsHorizontalScrollIndicator 28 | @property (nonatomic, strong, readonly) UIScrollView *(^showHIndicator)(BOOL); 29 | //showsVerticalScrollIndicator 30 | @property (nonatomic, strong, readonly) UIScrollView *(^showVIndicator)(BOOL); 31 | 32 | 33 | @property (nonatomic, strong, readonly) UIScrollView *(^scrollIndecatorInset)(UIEdgeInsets); 34 | @property (nonatomic, strong, readonly) UIScrollView *(^IndicatorStyle)(UIScrollViewIndicatorStyle); 35 | @property (nonatomic, strong, readonly) UIScrollView *(^deceleratRate)(CGFloat); 36 | @property (nonatomic, strong, readonly) UIScrollView *(^ZoomScale)(CGFloat); 37 | @property (nonatomic, strong, readonly) UIScrollView *(^minZoomScale)(CGFloat); 38 | @property (nonatomic, strong, readonly) UIScrollView *(^maxZoomScale)(CGFloat); 39 | @property (nonatomic, strong, readonly) UIScrollView *(^bounceZoom)(BOOL); 40 | @property (nonatomic, strong, readonly) UIScrollView *(^scrollToTop)(BOOL); 41 | 42 | 43 | 44 | //- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; 45 | @property (nonatomic, strong, readonly) UIScrollView *(^setContentOffsetAnimated)(CGPoint, BOOL); 46 | 47 | //- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated; 48 | @property (nonatomic, strong, readonly) UIScrollView *(^scrollRectToVisibleAnimated)(CGRect, BOOL); 49 | 50 | //- (void)setZoomScale:(CGFloat)scale animated:(BOOL)animated 51 | @property (nonatomic, strong, readonly) UIScrollView *(^setZoomScaleAnimated)(CGFloat, BOOL); 52 | 53 | //- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated 54 | @property (nonatomic, strong, readonly) UIScrollView *(^zoomToRectAnimated)(CGRect, BOOL); 55 | @end 56 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIScrollView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIScrollView+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIScrollView+XRCategory.h" 9 | 10 | @implementation UIScrollView (XRCategory) 11 | 12 | 13 | + (instancetype)create:(void (^)(UIScrollView *))block{ 14 | UIScrollView *obj = [[UIScrollView alloc] init]; 15 | if (block) block(obj); 16 | return obj; 17 | } 18 | 19 | - (UIScrollView *(^)(CGPoint))ContentOffset { 20 | return ^(CGPoint offset){ 21 | self.contentOffset = offset; 22 | return self; 23 | }; 24 | } 25 | 26 | - (UIScrollView *(^)(CGSize))ContentSize { 27 | return ^(CGSize size){ 28 | self.contentSize = size; 29 | return self; 30 | }; 31 | } 32 | 33 | - (UIScrollView *(^)(UIEdgeInsets))ContentInset { 34 | return ^(UIEdgeInsets edge){ 35 | self.contentInset = edge; 36 | return self; 37 | }; 38 | } 39 | 40 | - (UIScrollView *(^)(id))Delegate { 41 | return ^(id obj) { 42 | self.delegate = obj; 43 | return self; 44 | }; 45 | } 46 | 47 | - (UIScrollView *(^)(BOOL))bounce { 48 | return ^(BOOL b) { 49 | self.bounces = b; 50 | return self; 51 | }; 52 | } 53 | 54 | - (UIScrollView *(^)(BOOL))alwaysBounceV { 55 | return ^(BOOL b) { 56 | self.alwaysBounceVertical = b; 57 | return self; 58 | }; 59 | } 60 | 61 | - (UIScrollView *(^)(BOOL))alwaysBounceH { 62 | return ^(BOOL b) { 63 | self.alwaysBounceHorizontal = b; 64 | return self; 65 | }; 66 | } 67 | 68 | - (UIScrollView *(^)(BOOL))pagingEnable { 69 | return ^(BOOL b) { 70 | self.pagingEnabled = b; 71 | return self; 72 | }; 73 | } 74 | 75 | - (UIScrollView *(^)(BOOL))scrollEnable { 76 | return ^(BOOL b) { 77 | self.scrollEnabled = b; 78 | return self; 79 | }; 80 | } 81 | 82 | - (UIScrollView *(^)(BOOL))scrollToTop { 83 | return ^(BOOL b) { 84 | self.scrollsToTop = b; 85 | return self; 86 | }; 87 | } 88 | 89 | - (UIScrollView *(^)(BOOL))showHIndicator { 90 | return ^(BOOL b) { 91 | self.showsHorizontalScrollIndicator = b; 92 | return self; 93 | }; 94 | } 95 | 96 | - (UIScrollView *(^)(BOOL))showVIndicator { 97 | return ^(BOOL b) { 98 | self.showsVerticalScrollIndicator = b; 99 | return self; 100 | }; 101 | } 102 | 103 | - (UIScrollView *(^)(UIEdgeInsets))scrollIndecatorInset { 104 | return ^(UIEdgeInsets inset) { 105 | self.scrollIndicatorInsets = inset; 106 | return self; 107 | }; 108 | } 109 | 110 | - (UIScrollView *(^)(UIScrollViewIndicatorStyle))IndicatorStyle { 111 | return ^(UIScrollViewIndicatorStyle style) { 112 | self.indicatorStyle = style; 113 | return self; 114 | }; 115 | } 116 | 117 | - (UIScrollView *(^)(CGFloat))deceleratRate { 118 | return ^(CGFloat rate) { 119 | self.decelerationRate = rate; 120 | return self; 121 | }; 122 | } 123 | 124 | - (UIScrollView *(^)(CGFloat))ZoomScale { 125 | return ^(CGFloat scale) { 126 | self.zoomScale = scale; 127 | return self; 128 | }; 129 | } 130 | 131 | - (UIScrollView *(^)(CGFloat))minZoomScale { 132 | return ^(CGFloat scale) { 133 | self.minimumZoomScale = scale; 134 | return self; 135 | }; 136 | } 137 | 138 | - (UIScrollView *(^)(CGFloat))maxZoomScale { 139 | return ^(CGFloat scale) { 140 | self.maximumZoomScale = scale; 141 | return self; 142 | }; 143 | } 144 | 145 | - (UIScrollView *(^)(BOOL))bounceZoom { 146 | return ^(BOOL b) { 147 | self.bouncesZoom = b; 148 | return self; 149 | }; 150 | } 151 | 152 | 153 | - (UIScrollView *(^)(CGPoint, BOOL))setContentOffsetAnimated { 154 | return ^(CGPoint offset, BOOL b) { 155 | [self setContentOffset:offset animated:b]; 156 | return self; 157 | }; 158 | } 159 | 160 | - (UIScrollView *(^)(CGRect, BOOL))scrollRectToVisibleAnimated { 161 | return ^(CGRect rect, BOOL b) { 162 | [self scrollRectToVisible:rect animated:b]; 163 | return self; 164 | }; 165 | } 166 | 167 | - (UIScrollView *(^)(CGFloat, BOOL))setZoomScaleAnimated { 168 | return ^(CGFloat scale, BOOL b) { 169 | [self setZoomScale:scale animated:b]; 170 | return self; 171 | }; 172 | } 173 | 174 | - (UIScrollView *(^)(CGRect, BOOL))zoomToRectAnimated { 175 | return ^(CGRect rect, BOOL b) { 176 | [self zoomToRect:rect animated:b]; 177 | return self; 178 | }; 179 | } 180 | 181 | @end 182 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UITableView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITableView (XRCategory) 12 | + (instancetype)create:(void(^)(UITableView *obj))block; 13 | + (instancetype)createWithStyle:(UITableViewStyle)style :(void(^)(UITableView *obj))block; 14 | @property (nonatomic, strong, readonly) UITableView *(^DataSource)(id); 15 | @property (nonatomic, strong, readonly) UITableView *(^Delegate)(id); 16 | @property (nonatomic, strong, readonly) UITableView *(^RowHeight)(CGFloat); 17 | @property (nonatomic, strong, readonly) UITableView *(^sectionHeadHeight)(CGFloat); 18 | @property (nonatomic, strong, readonly) UITableView *(^sectionFootHeight)(CGFloat); 19 | @property (nonatomic, strong, readonly) UITableView *(^estimateRowHeight)(CGFloat); 20 | @property (nonatomic, strong, readonly) UITableView *(^separatInset)(UIEdgeInsets); 21 | @property (nonatomic, strong, readonly) UITableView *(^bgView)(UIView *); 22 | @property (nonatomic, strong, readonly) UITableView *(^edit)(BOOL); 23 | @property (nonatomic, strong, readonly) UITableView *(^allowSelect)(BOOL); 24 | @property (nonatomic, strong, readonly) UITableView *(^allowMultSelect)(BOOL); 25 | @property (nonatomic, strong, readonly) UITableView *(^allowSelectDuringEdit)(BOOL); 26 | @property (nonatomic, strong, readonly) UITableView *(^allowMultSelectDuringEdit)(BOOL); 27 | @property (nonatomic, strong, readonly) UITableView *(^SectionIndexColor)(UIColor *); 28 | @property (nonatomic, strong, readonly) UITableView *(^sectionIndexBgColor)(UIColor *); 29 | @property (nonatomic, strong, readonly) UITableView *(^sectionIndexTrackBgColor)(UIColor *); 30 | @property (nonatomic, strong, readonly) UITableView *(^separatStyle)(UITableViewCellSeparatorStyle); 31 | @property (nonatomic, strong, readonly) UITableView *(^separatColor)(UIColor *); 32 | 33 | 34 | 35 | 36 | /** 37 | * scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated 38 | */ 39 | @property (nonatomic, strong, readonly) UITableView *(^scrollToIndexPathAtPositionAnimated)(NSIndexPath *, UITableViewScrollPosition, BOOL); 40 | 41 | /** 42 | * reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation 43 | */ 44 | @property (nonatomic, strong, readonly) UITableView *(^reloadSectionsWithAnimation)(NSIndexSet *, UITableViewRowAnimation); 45 | 46 | /** 47 | * reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 48 | */ 49 | @property (nonatomic, strong, readonly) UITableView *(^reloadRowsAtIndexPathsWithAnimation)(NSArray *, UITableViewRowAnimation); 50 | 51 | /** 52 | * moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath 53 | */ 54 | @property (nonatomic, strong, readonly) UITableView *(^moveRowAtIndexPathToIndexPath)(NSIndexPath *, NSIndexPath *); 55 | 56 | /** 57 | * selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition 58 | */ 59 | @property (nonatomic, strong, readonly) UITableView *(^selecRowAtIndexPathAnimatedScrollPosition)(NSIndexPath *, BOOL, UITableViewScrollPosition); 60 | 61 | /** 62 | * deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated 63 | */ 64 | @property (nonatomic, strong, readonly) UITableView *(^deselecRowAtIndexPathAnimated)(NSIndexPath *, BOOL); 65 | 66 | /** 67 | * setEditing:(BOOL)editing animated:(BOOL)animated 68 | */ 69 | @property (nonatomic, strong, readonly) UITableView *(^setEditingAnimated)(BOOL, BOOL); 70 | 71 | /** 72 | * registerNib:(nullable UINib *)nib forCellReuseIdentifier:(NSString *)identifier 73 | */ 74 | @property (nonatomic, strong, readonly) UITableView *(^registNibForCellId)(UINib *, NSString *); 75 | 76 | /** 77 | * registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier 78 | */ 79 | @property (nonatomic, strong, readonly) UITableView *(^registClassForCellId)(Class, NSString *); 80 | 81 | /** 82 | * registerNib:(nullable UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier 83 | */ 84 | @property (nonatomic, strong, readonly) UITableView *(^registNibForHeadFootViewId)(UINib *, NSString *); 85 | 86 | /** 87 | * registerClass:(nullable UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier 88 | */ 89 | @property (nonatomic, strong, readonly) UITableView *(^registClassForHeadFootViewId)(Class, NSString *); 90 | 91 | 92 | /** 93 | * numberOfRowsInSection:(NSInteger)section 94 | */ 95 | @property (nonatomic, strong, readonly) NSInteger(^numOfRowsInSection)(NSInteger); 96 | 97 | 98 | /** 99 | * indexPathForRowAtPoint:(CGPoint)point 100 | */ 101 | @property (nonatomic, strong, readonly) NSIndexPath *(^indexPathForRowAtPoint)(CGPoint); 102 | 103 | 104 | /** 105 | * indexPathForCell:(UITableViewCell *)cell 106 | */ 107 | @property (nonatomic, strong, readonly) NSIndexPath *(^indexPathForCell)(UITableViewCell *); 108 | 109 | /** 110 | * indexPathsForRowsInRect:(CGRect)rect 111 | */ 112 | @property (nonatomic, strong, readonly) NSArray *(^indexPathsForRowsInRect)(CGRect); 113 | 114 | 115 | /** 116 | * cellForRowAtIndexPath:(NSIndexPath *)indexPath 117 | */ 118 | @property (nonatomic, strong, readonly) UITableViewCell *(^cellForRowAtIndexPath)(NSIndexPath *); 119 | 120 | /** 121 | * headerViewForSection:(NSInteger)section 122 | */ 123 | @property (nonatomic, strong, readonly) UITableViewHeaderFooterView *(^headViewForSection)(NSInteger); 124 | 125 | /** 126 | * footerViewForSection:(NSInteger)section 127 | */ 128 | @property (nonatomic, strong, readonly) UITableViewHeaderFooterView *(^footViewForSection)(NSInteger); 129 | 130 | /** 131 | * dequeueReusableCellWithIdentifier:(NSString *)identifier 132 | */ 133 | @property (nonatomic, strong, readonly) UITableViewCell *(^dequeueReuseCellWithId)(NSString *); 134 | 135 | /** 136 | * dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath 137 | */ 138 | @property (nonatomic, strong, readonly) UITableViewCell *(^dequeueReuseCellWithIdForIndexPath)(NSString *, NSIndexPath *); 139 | 140 | /** 141 | * dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier 142 | */ 143 | @property (nonatomic, strong, readonly) UITableViewHeaderFooterView *(^dequeueReuseHeadFootViewWithId)(NSString *); 144 | 145 | @end 146 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UITableView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+XRCategory.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import "UITableView+XRCategory.h" 10 | 11 | @implementation UITableView (XRCategory) 12 | 13 | 14 | 15 | + (instancetype)create:(void (^)(UITableView *))block{ 16 | UITableView *obj = [[UITableView alloc] init]; 17 | if (block) block(obj); 18 | return obj; 19 | } 20 | 21 | 22 | + (instancetype)createWithStyle:(UITableViewStyle)style :(void(^)(UITableView *obj))block { 23 | UITableView *obj = [[UITableView alloc] initWithFrame:CGRectZero style:style]; 24 | if (block) block(obj); 25 | return obj; 26 | } 27 | 28 | 29 | - (UITableView *(^)(id))DataSource{ 30 | return ^(id dataSource){ 31 | self.dataSource = dataSource; 32 | return self; 33 | }; 34 | } 35 | 36 | - (UITableView *(^)(id))Delegate{ 37 | return ^(id delegate){ 38 | self.delegate = delegate; 39 | return self; 40 | }; 41 | } 42 | 43 | - (UITableView *(^)(CGFloat))RowHeight { 44 | return ^(CGFloat height){ 45 | self.rowHeight = height; 46 | return self; 47 | }; 48 | } 49 | 50 | - (UITableView *(^)(CGFloat))sectionHeadHeight { 51 | return ^(CGFloat height){ 52 | self.sectionHeaderHeight = height; 53 | return self; 54 | }; 55 | } 56 | 57 | - (UITableView *(^)(CGFloat))sectionFootHeight { 58 | return ^(CGFloat height){ 59 | self.sectionFooterHeight = height; 60 | return self; 61 | }; 62 | } 63 | 64 | - (UITableView *(^)(CGFloat))estimateRowHeight { 65 | return ^(CGFloat height){ 66 | self.estimatedRowHeight = height; 67 | return self; 68 | }; 69 | } 70 | 71 | - (UITableView *(^)(UIEdgeInsets))separatInset { 72 | return ^(UIEdgeInsets inset) { 73 | self.separatorInset = inset; 74 | return self; 75 | }; 76 | } 77 | 78 | - (UITableView *(^)(UIView *))bgView { 79 | return ^(UIView *view) { 80 | self.backgroundView = view; 81 | return self; 82 | }; 83 | } 84 | 85 | - (UITableView *(^)(BOOL))edit { 86 | return ^(BOOL b) { 87 | self.editing = b; 88 | return self; 89 | }; 90 | } 91 | 92 | - (UITableView *(^)(BOOL))allowSelect { 93 | return ^(BOOL b) { 94 | self.allowsSelection = b; 95 | return self; 96 | }; 97 | } 98 | - (UITableView *(^)(BOOL))allowMultSelect { 99 | return ^(BOOL b) { 100 | self.allowsMultipleSelection = b; 101 | return self; 102 | }; 103 | } 104 | - (UITableView *(^)(BOOL))allowSelectDuringEdit { 105 | return ^(BOOL b) { 106 | self.allowsSelectionDuringEditing = b; 107 | return self; 108 | }; 109 | } 110 | - (UITableView *(^)(BOOL))allowMultSelectDuringEdit { 111 | return ^(BOOL b) { 112 | self.allowsMultipleSelectionDuringEditing = b; 113 | return self; 114 | }; 115 | } 116 | 117 | - (UITableView *(^)(UIColor *))SectionIndexColor { 118 | return ^(UIColor *color) { 119 | self.sectionIndexColor = color; 120 | return self; 121 | }; 122 | } 123 | 124 | - (UITableView *(^)(UIColor *))sectionIndexBgColor { 125 | return ^(UIColor *color) { 126 | self.sectionIndexBackgroundColor = color; 127 | return self; 128 | }; 129 | } 130 | 131 | - (UITableView *(^)(UIColor *))sectionIndexTrackBgColor { 132 | return ^(UIColor *color) { 133 | self.sectionIndexTrackingBackgroundColor = color; 134 | return self; 135 | }; 136 | } 137 | 138 | - (UITableView *(^)(UITableViewCellSeparatorStyle))separatStyle { 139 | return ^(UITableViewCellSeparatorStyle style) { 140 | self.separatorStyle = style; 141 | return self; 142 | }; 143 | } 144 | 145 | - (UITableView *(^)(UIColor *))separatColor { 146 | return ^(UIColor *color) { 147 | self.separatorColor = color; 148 | return self; 149 | }; 150 | } 151 | 152 | 153 | - (UITableView *(^)(NSIndexPath *, UITableViewScrollPosition, BOOL))scrollToIndexPathAtPositionAnimated { 154 | return ^(NSIndexPath *indexPath, UITableViewScrollPosition position, BOOL b){ 155 | [self scrollToRowAtIndexPath:indexPath atScrollPosition:position animated:b]; 156 | return self; 157 | }; 158 | } 159 | 160 | - (UITableView *(^)(NSIndexSet *, UITableViewRowAnimation))reloadSectionsWithAnimation { 161 | return ^(NSIndexSet *sections, UITableViewRowAnimation animation){ 162 | [self reloadSections:sections withRowAnimation:animation]; 163 | return self; 164 | }; 165 | } 166 | 167 | - (UITableView *(^)(NSArray *, UITableViewRowAnimation))reloadRowsAtIndexPathsWithAnimation { 168 | return ^(NSArray *indexPaths, UITableViewRowAnimation aniamtion){ 169 | [self reloadRowsAtIndexPaths:indexPaths withRowAnimation:aniamtion]; 170 | return self; 171 | }; 172 | } 173 | 174 | - (UITableView *(^)(NSIndexPath *, NSIndexPath *))moveRowAtIndexPathToIndexPath { 175 | return ^(NSIndexPath *fromIndexPath, NSIndexPath *toIndexPath){ 176 | [self moveRowAtIndexPath:fromIndexPath toIndexPath:toIndexPath]; 177 | return self; 178 | }; 179 | } 180 | 181 | - (UITableView *(^)(NSIndexPath *, BOOL, UITableViewScrollPosition))selecRowAtIndexPathAnimatedScrollPosition { 182 | return ^(NSIndexPath *indexPath, BOOL b, UITableViewScrollPosition position){ 183 | [self selectRowAtIndexPath:indexPath animated:b scrollPosition:position]; 184 | return self; 185 | }; 186 | } 187 | 188 | 189 | - (UITableView *(^)(NSIndexPath *, BOOL))deselecRowAtIndexPathAnimated { 190 | return ^(NSIndexPath *indexPath, BOOL b){ 191 | [self deselectRowAtIndexPath:indexPath animated:b]; 192 | return self; 193 | }; 194 | } 195 | 196 | - (UITableView *(^)(BOOL, BOOL))setEditingAnimated { 197 | return ^(BOOL b1, BOOL b2){ 198 | [self setEditing:b1 animated:b2]; 199 | return self; 200 | }; 201 | } 202 | 203 | - (UITableView *(^)(UINib *, NSString *))registNibForCellId { 204 | return ^(UINib *nib, NSString *Id){ 205 | [self registerNib:nib forCellReuseIdentifier:Id]; 206 | return self; 207 | }; 208 | } 209 | 210 | - (UITableView *(^)(Class, NSString *))registClassForCellId { 211 | return ^(Class class, NSString *Id){ 212 | [self registerClass:class forCellReuseIdentifier:Id]; 213 | return self; 214 | }; 215 | } 216 | 217 | 218 | - (UITableView *(^)(UINib *, NSString *))registNibForHeadFootViewId { 219 | return ^(UINib *nib, NSString *Id){ 220 | [self registerNib:nib forHeaderFooterViewReuseIdentifier:Id]; 221 | return self; 222 | }; 223 | } 224 | 225 | - (UITableView *(^)(Class, NSString *))registClassForHeadFootViewId { 226 | return ^(Class class, NSString *Id){ 227 | [self registerClass:class forHeaderFooterViewReuseIdentifier:Id]; 228 | return self; 229 | }; 230 | } 231 | 232 | - (NSInteger (^)(NSInteger))numOfRowsInSection { 233 | return ^(NSInteger secion){ 234 | return [self numberOfRowsInSection:secion]; 235 | }; 236 | } 237 | 238 | - (NSIndexPath *(^)(CGPoint))indexPathForRowAtPoint { 239 | return ^(CGPoint point){ 240 | return [self indexPathForRowAtPoint:point]; 241 | }; 242 | } 243 | 244 | - (NSIndexPath *(^)(UITableViewCell *))indexPathForCell { 245 | return ^(UITableViewCell *cell){ 246 | return [self indexPathForCell:cell]; 247 | }; 248 | } 249 | 250 | - (NSArray *(^)(CGRect))indexPathsForRowsInRect { 251 | return ^(CGRect rect){ 252 | return [self indexPathsForRowsInRect:rect]; 253 | }; 254 | } 255 | 256 | - (UITableViewCell *(^)(NSIndexPath *))cellForRowAtIndexPath { 257 | return ^(NSIndexPath *indexPath){ 258 | return [self cellForRowAtIndexPath:indexPath]; 259 | }; 260 | } 261 | 262 | - (UITableViewCell *(^)(NSString *))dequeueReuseCellWithId { 263 | return ^(NSString *Id){ 264 | return [self dequeueReusableCellWithIdentifier:Id]; 265 | }; 266 | } 267 | 268 | - (UITableViewCell *(^)(NSString *, NSIndexPath *))dequeueReuseCellWithIdForIndexPath { 269 | return ^(NSString *Id, NSIndexPath *indexPath){ 270 | return [self dequeueReusableCellWithIdentifier:Id forIndexPath:indexPath]; 271 | }; 272 | } 273 | 274 | - (UITableViewHeaderFooterView *(^)(NSInteger))headViewForSection { 275 | return ^(NSInteger section){ 276 | return [self headerViewForSection:section]; 277 | }; 278 | } 279 | 280 | - (UITableViewHeaderFooterView *(^)(NSInteger))footViewForSection { 281 | return ^(NSInteger section){ 282 | return [self footerViewForSection:section]; 283 | }; 284 | } 285 | 286 | - (UITableViewHeaderFooterView *(^)(NSString *))dequeueReuseHeadFootViewWithId { 287 | return ^(NSString *Id){ 288 | return [self dequeueReusableHeaderFooterViewWithIdentifier:Id]; 289 | }; 290 | } 291 | 292 | @end 293 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UITextField+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UITextField (XRCategory) 11 | + (instancetype)create:(void(^)(UITextField *obj))block; 12 | 13 | 14 | //text 15 | @property (nonatomic, strong, readonly) UITextField *(^Text)(NSString *); 16 | @property (nonatomic, strong, readonly) UITextField *(^attributeTxt)(NSAttributedString *); 17 | @property (nonatomic, strong, readonly) UITextField *(^TextColor)(UIColor *); 18 | 19 | //font 20 | @property (nonatomic, strong, readonly) UITextField *(^Font)(UIFont *); 21 | @property (nonatomic, strong, readonly) UITextField *(^fontSize)(NSInteger); 22 | 23 | @property (nonatomic, strong, readonly) UITextField *(^TextAlignment)(NSTextAlignment); 24 | @property (nonatomic, strong, readonly) UITextField *(^BorderStyle)(UITextBorderStyle); 25 | @property (nonatomic, strong, readonly) UITextField *(^defaultTxtAttributes)(NSDictionary *); 26 | 27 | //placeholder 28 | @property (nonatomic, strong, readonly) UITextField *(^placeHolder)(NSString *); 29 | @property (nonatomic, strong, readonly) UITextField *(^attributePlaceholder)(NSAttributedString *); 30 | @property (nonatomic, strong, readonly) UITextField *(^clearOnBeginEdit)(BOOL); 31 | 32 | //adjustsFontSizeToFitWidth 33 | @property (nonatomic, strong, readonly) UITextField *(^adjustFontToWidth)(BOOL); 34 | @property (nonatomic, strong, readonly) UITextField *(^Delegate)(id); 35 | 36 | //background 37 | @property (nonatomic, strong, readonly) UITextField *(^bgImage)(UIImage *); 38 | //disableBackground 39 | @property (nonatomic, strong, readonly) UITextField *(^disableBgImage)(UIImage *); 40 | 41 | 42 | @property (nonatomic, strong, readonly) UITextField *(^allowEditTxtAttribute)(BOOL); 43 | @property (nonatomic, strong, readonly) UITextField *(^clearBtnMode)(UITextFieldViewMode); 44 | 45 | //leftView 46 | @property (nonatomic, strong, readonly) UITextField *(^leftV)(UIView *); 47 | //leftViewMode 48 | @property (nonatomic, strong, readonly) UITextField *(^leftVMode)(UITextFieldViewMode); 49 | //rightView 50 | @property (nonatomic, strong, readonly) UITextField *(^rightV)(UIView *); 51 | //rightViewMode 52 | @property (nonatomic, strong, readonly) UITextField *(^rightVMode)(UITextFieldViewMode); 53 | 54 | //drawPlaceholderInRect 55 | @property (nonatomic, strong, readonly) UITextField *(^drawPlaceholder)(CGRect); 56 | //drawTextInRect 57 | @property (nonatomic, strong, readonly) UITextField *(^drawText)(CGRect); 58 | 59 | //inputView 60 | @property (nonatomic, strong, readonly) UITextField *(^inputV)(UIView *); 61 | //inputAccessoryView 62 | @property (nonatomic, strong, readonly) UITextField *(^inputAccessoryV)(UIView *); 63 | @end 64 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UITextField+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UITextField+XRCategory.h" 9 | 10 | @implementation UITextField (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UITextField *))block{ 13 | UITextField *obj = [[UITextField alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | - (UITextField *(^)(NSString *))Text{ 19 | return ^(NSString *text){ 20 | self.text = text; 21 | return self; 22 | }; 23 | } 24 | 25 | - (UITextField *(^)(NSAttributedString *))attributeTxt{ 26 | return ^(NSAttributedString *text){ 27 | self.attributedText = text; 28 | return self; 29 | }; 30 | } 31 | 32 | - (UITextField *(^)(UIColor *))TextColor{ 33 | return ^(UIColor *color){ 34 | self.textColor = color; 35 | return self; 36 | }; 37 | } 38 | 39 | - (UITextField *(^)(UIFont *))Font{ 40 | return ^(UIFont *font){ 41 | self.font = font; 42 | return self; 43 | }; 44 | } 45 | 46 | - (UITextField *(^)(NSInteger))fontSize{ 47 | return ^(NSInteger size){ 48 | self.font = [UIFont systemFontOfSize:size]; 49 | return self; 50 | }; 51 | } 52 | 53 | - (UITextField *(^)(NSTextAlignment))TextAlignment{ 54 | return ^(NSTextAlignment alignment){ 55 | self.textAlignment = alignment; 56 | return self; 57 | }; 58 | } 59 | 60 | - (UITextField *(^)(UITextBorderStyle))BorderStyle{ 61 | return ^(UITextBorderStyle style){ 62 | self.borderStyle= style; 63 | return self; 64 | }; 65 | } 66 | 67 | - (UITextField *(^)(NSDictionary *))defaultTxtAttributes{ 68 | return ^(NSDictionary *attributes){ 69 | self.defaultTextAttributes = attributes; 70 | return self; 71 | }; 72 | } 73 | 74 | - (UITextField *(^)(NSString *))placeHolder{ 75 | return ^(NSString *text){ 76 | self.placeholder = text; 77 | return self; 78 | }; 79 | } 80 | 81 | - (UITextField *(^)(NSAttributedString *))attributePlaceholder{ 82 | return ^(NSAttributedString *text){ 83 | self.attributedPlaceholder = text; 84 | return self; 85 | }; 86 | } 87 | 88 | - (UITextField *(^)(BOOL))clearOnBeginEdit{ 89 | return ^(BOOL b){ 90 | self.clearsOnBeginEditing = b; 91 | return self; 92 | }; 93 | } 94 | 95 | - (UITextField *(^)(BOOL))adjustFontToWidth{ 96 | return ^(BOOL b){ 97 | self.adjustsFontSizeToFitWidth = b; 98 | return self; 99 | }; 100 | } 101 | 102 | - (UITextField *(^)(id))Delegate { 103 | return ^(id delegate) { 104 | self.delegate = delegate; 105 | return self; 106 | }; 107 | } 108 | 109 | - (UITextField *(^)(UIImage *))bgImage { 110 | return ^(UIImage *image){ 111 | self.background = image; 112 | return self; 113 | }; 114 | } 115 | 116 | - (UITextField *(^)(UIImage *))disableBgImage { 117 | return ^(UIImage *image){ 118 | self.disabledBackground = image; 119 | return self; 120 | }; 121 | } 122 | 123 | 124 | - (UITextField *(^)(BOOL))allowEditTxtAttribute { 125 | return ^(BOOL b){ 126 | self.allowsEditingTextAttributes = b; 127 | return self; 128 | }; 129 | } 130 | 131 | - (UITextField *(^)(UITextFieldViewMode))clearBtnMode { 132 | return ^(UITextFieldViewMode mode){ 133 | self.clearButtonMode = mode; 134 | return self; 135 | }; 136 | } 137 | 138 | - (UITextField *(^)(UIView *))leftV { 139 | return ^(UIView *view){ 140 | self.leftView = view; 141 | return self; 142 | }; 143 | } 144 | 145 | - (UITextField *(^)(UITextFieldViewMode))leftVMode { 146 | return ^(UITextFieldViewMode mode){ 147 | self.leftViewMode = mode; 148 | return self; 149 | }; 150 | } 151 | 152 | - (UITextField *(^)(UIView *))rightV { 153 | return ^(UIView *view){ 154 | self.rightView = view; 155 | return self; 156 | }; 157 | } 158 | 159 | - (UITextField *(^)(UITextFieldViewMode))rightVMode { 160 | return ^(UITextFieldViewMode mode){ 161 | self.rightViewMode = mode; 162 | return self; 163 | }; 164 | } 165 | 166 | - (UITextField *(^)(CGRect))drawPlaceholder { 167 | return ^(CGRect rect){ 168 | [self drawPlaceholderInRect:rect]; 169 | return self; 170 | }; 171 | } 172 | 173 | - (UITextField *(^)(CGRect))drawText { 174 | return ^(CGRect rect){ 175 | [self drawTextInRect:rect]; 176 | return self; 177 | }; 178 | } 179 | 180 | - (UITextField *(^)(UIView *))inputV { 181 | return ^(UIView *view){ 182 | self.inputView = view; 183 | return self; 184 | }; 185 | } 186 | 187 | - (UITextField *(^)(UIView *))inputAccessoryV { 188 | return ^(UIView *view){ 189 | self.inputAccessoryView = view; 190 | return self; 191 | }; 192 | } 193 | @end 194 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UITextView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UITextView (XRCategory) 11 | 12 | + (instancetype)create:(void(^)(UITextView *obj))block; 13 | 14 | //text 15 | @property (nonatomic, strong, readonly) UITextView *(^Text)(NSString *); 16 | @property (nonatomic, strong, readonly) UITextView *(^attributeTxt)(NSAttributedString *); 17 | @property (nonatomic, strong, readonly) UITextView *(^TextColor)(UIColor *); 18 | 19 | //font 20 | @property (nonatomic, strong, readonly) UITextView *(^Font)(UIFont *); 21 | @property (nonatomic, strong, readonly) UITextView *(^fontSize)(NSInteger); 22 | 23 | @property (nonatomic, strong, readonly) UITextView *(^TextAlignment)(NSTextAlignment); 24 | @property (nonatomic, strong, readonly) UITextView *(^Delegate)(id); 25 | @property (nonatomic, strong, readonly) UITextView *(^allowEditTxtAttribute)(BOOL); 26 | 27 | //inputView 28 | @property (nonatomic, strong, readonly) UITextView *(^inputV)(UIView *); 29 | //inputAccessoryView 30 | @property (nonatomic, strong, readonly) UITextView *(^inputAccessoryV)(UIView *); 31 | 32 | 33 | @property (nonatomic, strong, readonly) UITextView *(^selectRange)(NSRange); 34 | @property (nonatomic, strong, readonly) UITextView *(^editAble)(BOOL); 35 | @property (nonatomic, strong, readonly) UITextView *(^selectAble)(BOOL); 36 | @property (nonatomic, strong, readonly) UITextView *(^dataDetectorType)(UIDataDetectorTypes); 37 | @property (nonatomic, strong, readonly) UITextView *(^txtContainerInset)(UIEdgeInsets); 38 | @property (nonatomic, strong, readonly) UITextView *(^linkTxtAttributes)(NSDictionary *); 39 | @property (nonatomic, strong, readonly) UITextView *(^scrollRangeToVisible)(NSRange); 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UITextView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/13. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UITextView+XRCategory.h" 9 | 10 | @implementation UITextView (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UITextView *))block{ 13 | UITextView *obj = [[UITextView alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | 19 | - (UITextView *(^)(NSString *))Text{ 20 | return ^(NSString *text){ 21 | self.text = text; 22 | return self; 23 | }; 24 | } 25 | 26 | - (UITextView *(^)(NSAttributedString *))attributeTxt{ 27 | return ^(NSAttributedString *text){ 28 | self.attributedText = text; 29 | return self; 30 | }; 31 | } 32 | 33 | - (UITextView *(^)(UIColor *))TextColor{ 34 | return ^(UIColor *color){ 35 | self.textColor = color; 36 | return self; 37 | }; 38 | } 39 | 40 | - (UITextView *(^)(UIFont *))Font{ 41 | return ^(UIFont *font){ 42 | self.font = font; 43 | return self; 44 | }; 45 | } 46 | 47 | - (UITextView *(^)(NSInteger))fontSize{ 48 | return ^(NSInteger size){ 49 | self.font = [UIFont systemFontOfSize:size]; 50 | return self; 51 | }; 52 | } 53 | 54 | - (UITextView *(^)(NSTextAlignment))TextAlignment{ 55 | return ^(NSTextAlignment alignment){ 56 | self.textAlignment = alignment; 57 | return self; 58 | }; 59 | } 60 | 61 | - (UITextView *(^)(id))Delegate { 62 | return ^(id delegate) { 63 | self.delegate = delegate; 64 | return self; 65 | }; 66 | } 67 | 68 | - (UITextView *(^)(BOOL))allowEditTxtAttribute { 69 | return ^(BOOL b){ 70 | self.allowsEditingTextAttributes = b; 71 | return self; 72 | }; 73 | } 74 | 75 | - (UITextView *(^)(UIView *))inputV { 76 | return ^(UIView *view){ 77 | self.inputView = view; 78 | return self; 79 | }; 80 | } 81 | 82 | - (UITextView *(^)(UIView *))inputAccessoryV { 83 | return ^(UIView *view){ 84 | self.inputAccessoryView = view; 85 | return self; 86 | }; 87 | } 88 | 89 | - (UITextView *(^)(NSRange))selectRange { 90 | return ^(NSRange range){ 91 | self.selectedRange = range; 92 | return self; 93 | }; 94 | } 95 | 96 | - (UITextView *(^)(BOOL))editAble { 97 | return ^(BOOL b){ 98 | self.editable = b; 99 | return self; 100 | }; 101 | } 102 | 103 | - (UITextView *(^)(BOOL))selectAble { 104 | return ^(BOOL b){ 105 | self.selectable = b; 106 | return self; 107 | }; 108 | } 109 | 110 | - (UITextView *(^)(UIDataDetectorTypes))dataDetectorType { 111 | return ^(UIDataDetectorTypes type){ 112 | self.dataDetectorTypes = type; 113 | return self; 114 | }; 115 | } 116 | 117 | - (UITextView *(^)(UIEdgeInsets))txtContainerInset { 118 | return ^(UIEdgeInsets edge){ 119 | self.textContainerInset = edge; 120 | return self; 121 | }; 122 | } 123 | 124 | - (UITextView *(^)(NSDictionary *))linkTxtAttributes { 125 | return ^(NSDictionary *attributes){ 126 | self.linkTextAttributes = attributes; 127 | return self; 128 | }; 129 | } 130 | 131 | - (UITextView *(^)(NSRange))scrollRangeToVisible { 132 | return ^(NSRange range){ 133 | [self scrollRangeToVisible:range]; 134 | return self; 135 | }; 136 | } 137 | @end 138 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIView+XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+XRCategory.h 3 | // 4 | // Created by 肖睿 on 16/4/12. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIView (XRCategory) 11 | 12 | + (instancetype)create:(void(^)(UIView *obj))block; 13 | 14 | @property (nonatomic, assign, readonly) CGFloat X; 15 | @property (nonatomic, assign, readonly) CGFloat Y; 16 | @property (nonatomic, assign, readonly) CGFloat Width; 17 | @property (nonatomic, assign, readonly) CGFloat Height; 18 | @property (nonatomic, assign, readonly) CGFloat CenterX; 19 | @property (nonatomic, assign, readonly) CGFloat CenterY; 20 | 21 | @property (nonatomic, strong, readonly) UIView *(^Frame)(CGRect);//frame 22 | @property (nonatomic, strong, readonly) UIView *(^frameEle)(CGFloat, CGFloat, CGFloat, CGFloat);//frame 23 | @property (nonatomic, strong, readonly) UIView *(^x)(CGFloat);//frame.origin.x 24 | @property (nonatomic, strong, readonly) UIView *(^y)(CGFloat);//frame.origin.y 25 | @property (nonatomic, strong, readonly) UIView *(^width)(CGFloat);//frame.origin.width 26 | @property (nonatomic, strong, readonly) UIView *(^height)(CGFloat);//frame.origin.height 27 | @property (nonatomic, strong, readonly) UIView *(^Bounds)(CGRect);//bounds 28 | @property (nonatomic, strong, readonly) UIView *(^boundsEle)(CGFloat, CGFloat, CGFloat, CGFloat);//bounds 29 | @property (nonatomic, strong, readonly) UIView *(^Center)(CGPoint);//center 30 | @property (nonatomic, strong, readonly) UIView *(^centerEle)(CGFloat, CGFloat);//center 31 | @property (nonatomic, strong, readonly) UIView *(^centerX)(CGFloat);//center.x 32 | @property (nonatomic, strong, readonly) UIView *(^centerY)(CGFloat);//center.y 33 | @property (nonatomic, strong, readonly) UIView *(^size)(CGSize);//frame.size 34 | @property (nonatomic, strong, readonly) UIView *(^sizeEle)(CGFloat, CGFloat);//frame.size 35 | @property (nonatomic, strong, readonly) UIView *(^origin)(CGPoint);//frame.origin 36 | @property (nonatomic, strong, readonly) UIView *(^originEle)(CGFloat, CGFloat);//frame.origin 37 | 38 | 39 | @property (nonatomic, strong, readonly) UIView *(^bgColor)(UIColor *);//backgroundColor 40 | @property (nonatomic, strong, readonly) UIView *(^bgColorRGB)(CGFloat, CGFloat, CGFloat, CGFloat);//backgroundColor 41 | @property (nonatomic, strong, readonly) UIView *(^Alpha)(CGFloat); 42 | @property (nonatomic, strong, readonly) UIView *(^Opaque)(CGFloat); 43 | @property (nonatomic, strong, readonly) UIView *(^cornerRadius)(CGFloat); 44 | @property (nonatomic, strong, readonly) UIView *(^maskToBounds)(BOOL); 45 | @property (nonatomic, strong, readonly) UIView *(^clipToBounds)(BOOL ); 46 | @property (nonatomic, strong, readonly) UIView *(^userInteractionEnable)(BOOL); 47 | @property (nonatomic, strong, readonly) UIView *(^hide)(BOOL); 48 | @property (nonatomic, strong, readonly) UIView *(^Tag)(NSInteger); 49 | @property (nonatomic, strong, readonly) UIView *(^ContentMode)(UIViewContentMode); 50 | @property (nonatomic, strong, readonly) UIView *(^multipleTouch)(BOOL); 51 | @property (nonatomic, strong, readonly) UIView *(^autoresizeSubViews)(BOOL); 52 | @property (nonatomic, strong, readonly) UIView *(^autoresizeMask)(BOOL); 53 | @property (nonatomic, strong, readonly) UIView *(^endEdit)(BOOL); 54 | 55 | @property (nonatomic, strong, readonly) UIView *(^removeFromSuperView)(); 56 | @property (nonatomic, strong, readonly) UIView *(^insertSubviewAtIndex)(UIView *, NSInteger); 57 | @property (nonatomic, strong, readonly) UIView *(^exchangeSubviewAtIndexWithIndex)(NSInteger, NSInteger); 58 | @property (nonatomic, strong, readonly) UIView *(^addSubview)(UIView *); 59 | @property (nonatomic, strong, readonly) UIView *(^insertSubviewBelowView)(UIView *, UIView *); 60 | @property (nonatomic, strong, readonly) UIView *(^insertSubviewAboveView)(UIView *, UIView *); 61 | @property (nonatomic, strong, readonly) UIView *(^bringSubviewToFront)(UIView *); 62 | @property (nonatomic, strong, readonly) UIView *(^sendSubviewToBack)(UIView *); 63 | 64 | 65 | /** 66 | * addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer 67 | * 68 | */ 69 | @property (nonatomic, strong, readonly) UIView *(^addGesture)(UIGestureRecognizer *); 70 | 71 | 72 | /** 73 | * removeGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer 74 | * 75 | */ 76 | @property (nonatomic, strong, readonly) UIView *(^removeGesture)(UIGestureRecognizer *); 77 | 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/UIView+XRCategory.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+XRCategory.m 3 | // 4 | // Created by 肖睿 on 16/4/12. 5 | // Copyright © 2016年 肖睿. All rights reserved. 6 | // 7 | 8 | #import "UIView+XRCategory.h" 9 | 10 | @implementation UIView (XRCategory) 11 | 12 | + (instancetype)create:(void (^)(UIView *))block{ 13 | UIView *obj = [[UIView alloc] init]; 14 | if (block) block(obj); 15 | return obj; 16 | } 17 | 18 | 19 | - (CGFloat)X { 20 | return self.frame.origin.x; 21 | } 22 | 23 | - (CGFloat)Y { 24 | return self.frame.origin.y; 25 | } 26 | 27 | - (CGFloat)Width { 28 | return self.frame.size.width; 29 | } 30 | 31 | - (CGFloat)Height { 32 | return self.frame.size.height; 33 | } 34 | 35 | - (CGFloat)CenterX { 36 | return self.center.x; 37 | } 38 | 39 | - (CGFloat)CenterY { 40 | return self.center.y; 41 | } 42 | 43 | 44 | - (UIView *(^)(CGRect))Frame { 45 | return ^(CGRect frame) { 46 | self.frame = frame; 47 | return self; 48 | }; 49 | } 50 | 51 | - (UIView *(^)(CGFloat, CGFloat, CGFloat, CGFloat))frameEle { 52 | return ^(CGFloat x, CGFloat y, CGFloat width, CGFloat height){ 53 | self.frame = CGRectMake(x, y, width, height); 54 | return self; 55 | }; 56 | } 57 | 58 | - (UIView *(^)(CGFloat))x { 59 | return ^(CGFloat x) { 60 | CGRect frame = self.frame; 61 | frame.origin.x = x; 62 | self.frame = frame; 63 | return self; 64 | }; 65 | } 66 | 67 | - (UIView *(^)(CGFloat))y { 68 | return ^(CGFloat y) { 69 | CGRect frame = self.frame; 70 | frame.origin.y = y; 71 | self.frame = frame; 72 | return self; 73 | }; 74 | } 75 | 76 | - (UIView *(^)(CGFloat))width { 77 | return ^(CGFloat width) { 78 | CGRect frame = self.frame; 79 | frame.size.width = width; 80 | self.frame = frame; 81 | return self; 82 | }; 83 | } 84 | 85 | - (UIView *(^)(CGFloat))height { 86 | return ^(CGFloat height) { 87 | CGRect frame = self.frame; 88 | frame.size.height = height; 89 | self.frame = frame; 90 | return self; 91 | }; 92 | } 93 | 94 | - (UIView *(^)(CGRect bounds))Bounds { 95 | return ^(CGRect bounds) { 96 | self.bounds = bounds; 97 | return self; 98 | }; 99 | } 100 | - (UIView *(^)(CGFloat x, CGFloat y, CGFloat width, CGFloat height))boundsEle { 101 | return ^(CGFloat x, CGFloat y, CGFloat width, CGFloat height){ 102 | self.bounds = CGRectMake(x, y, width, height); 103 | return self; 104 | }; 105 | } 106 | 107 | - (UIView *(^)(CGPoint center))Center { 108 | return ^(CGPoint center){ 109 | self.center = center; 110 | return self; 111 | }; 112 | } 113 | 114 | - (UIView *(^)(CGFloat x, CGFloat y))centerEle { 115 | return ^(CGFloat x, CGFloat y){ 116 | self.center = CGPointMake(x, y); 117 | return self; 118 | }; 119 | } 120 | 121 | - (UIView *(^)(CGFloat))centerX { 122 | return ^(CGFloat centerX) { 123 | CGPoint center = self.center; 124 | center.x = centerX; 125 | self.center = center; 126 | return self; 127 | }; 128 | } 129 | 130 | - (UIView *(^)(CGFloat))centerY { 131 | return ^(CGFloat centerY) { 132 | CGPoint center = self.center; 133 | center.y = centerY; 134 | self.center = center; 135 | return self; 136 | }; 137 | } 138 | 139 | - (UIView *(^)(CGSize size))size { 140 | return ^(CGSize size){ 141 | CGRect frame = self.frame; 142 | frame.size = size; 143 | self.frame = frame; 144 | return self; 145 | }; 146 | } 147 | 148 | - (UIView *(^)(CGFloat width, CGFloat height))sizeEle { 149 | return ^(CGFloat width, CGFloat height){ 150 | CGRect frame = self.frame; 151 | frame.size = CGSizeMake(width, height); 152 | self.frame = frame; 153 | return self; 154 | }; 155 | } 156 | 157 | - (UIView *(^)(CGPoint origin))origin { 158 | return ^(CGPoint origin){ 159 | CGRect frame = self.frame; 160 | frame.origin = origin; 161 | self.frame = frame; 162 | return self; 163 | }; 164 | } 165 | 166 | - (UIView *(^)(CGFloat x, CGFloat y))originEle { 167 | return ^(CGFloat x, CGFloat y){ 168 | CGRect frame = self.frame; 169 | frame.origin = CGPointMake(x, y); 170 | self.frame = frame; 171 | return self; 172 | }; 173 | } 174 | 175 | - (UIView *(^)(UIColor *))bgColor { 176 | return ^(UIColor *color) { 177 | self.backgroundColor = color; 178 | return self; 179 | }; 180 | } 181 | 182 | - (UIView *(^)(CGFloat, CGFloat, CGFloat, CGFloat))bgColorRGB { 183 | return ^(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha){ 184 | self.backgroundColor = [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:alpha]; 185 | return self; 186 | }; 187 | } 188 | 189 | - (UIView *(^)(CGFloat))Alpha { 190 | return ^(CGFloat alpha) { 191 | self.alpha = alpha; 192 | return self; 193 | }; 194 | } 195 | 196 | - (UIView *(^)(CGFloat))Opaque { 197 | return ^(CGFloat opaque) { 198 | self.opaque = opaque; 199 | return self; 200 | }; 201 | } 202 | 203 | - (UIView *(^)(CGFloat))cornerRadius { 204 | return ^(CGFloat radius) { 205 | self.layer.cornerRadius = radius; 206 | return self; 207 | }; 208 | } 209 | 210 | - (UIView *(^)(BOOL))maskToBounds { 211 | return ^(BOOL b) { 212 | self.layer.masksToBounds = b; 213 | return self; 214 | }; 215 | } 216 | 217 | - (UIView *(^)(BOOL))clipToBounds { 218 | return ^(BOOL b) { 219 | self.clipsToBounds = b; 220 | return self; 221 | }; 222 | } 223 | 224 | - (UIView *(^)(BOOL))userInteractionEnable { 225 | return ^(BOOL b) { 226 | self.userInteractionEnabled = b; 227 | return self; 228 | }; 229 | } 230 | 231 | - (UIView *(^)(BOOL))hide{ 232 | return ^(BOOL b) { 233 | self.hidden = b; 234 | return self; 235 | }; 236 | } 237 | 238 | - (UIView *(^)(NSInteger))Tag { 239 | return ^(NSInteger tag){ 240 | self.tag = tag; 241 | return self; 242 | }; 243 | } 244 | 245 | 246 | - (UIView *(^)(UIViewContentMode))ContentMode { 247 | return ^(UIViewContentMode mode){ 248 | self.contentMode = mode; 249 | return self; 250 | }; 251 | } 252 | 253 | - (UIView *(^)(BOOL))multipleTouch { 254 | return ^(BOOL b) { 255 | self.multipleTouchEnabled = b; 256 | return self; 257 | }; 258 | } 259 | 260 | - (UIView *(^)(BOOL))autoresizeSubViews { 261 | return ^(BOOL b) { 262 | self.autoresizesSubviews = b; 263 | return self; 264 | }; 265 | } 266 | 267 | - (UIView *(^)(BOOL))autoresizeMask { 268 | return ^(BOOL b) { 269 | self.autoresizingMask = b; 270 | return self; 271 | }; 272 | } 273 | 274 | 275 | - (UIView *(^)(BOOL))endEdit { 276 | return ^(BOOL b){ 277 | [self endEditing:b]; 278 | return self; 279 | }; 280 | } 281 | 282 | 283 | - (UIView *(^)())removeFromSuperView { 284 | return ^(){ 285 | [self removeFromSuperview]; 286 | return self; 287 | }; 288 | } 289 | 290 | - (UIView *(^)(UIView *, NSInteger))insertSubviewAtIndex { 291 | return ^(UIView *view, NSInteger index) { 292 | [self insertSubview:view atIndex:index]; 293 | return self; 294 | }; 295 | } 296 | 297 | - (UIView *(^)(UIView *, UIView *))insertSubviewBelowView { 298 | return ^(UIView *view1, UIView *view2) { 299 | [self insertSubview:view1 belowSubview:view2]; 300 | return self; 301 | }; 302 | } 303 | 304 | - (UIView *(^)(UIView *, UIView *))insertSubviewAboveView { 305 | return ^(UIView *view1, UIView *view2) { 306 | [self insertSubview:view1 aboveSubview:view2]; 307 | return self; 308 | }; 309 | } 310 | 311 | - (UIView *(^)(NSInteger , NSInteger))exchangeSubviewAtIndexWithIndex { 312 | return ^(NSInteger index1, NSInteger index2) { 313 | [self exchangeSubviewAtIndex:index1 withSubviewAtIndex:index2]; 314 | return self; 315 | }; 316 | } 317 | 318 | - (UIView *(^)(UIView *))addSubview { 319 | return ^(UIView *view) { 320 | [self addSubview:view]; 321 | return self; 322 | }; 323 | } 324 | 325 | - (UIView *(^)(UIView *))bringSubviewToFront { 326 | return ^(UIView *view) { 327 | [self bringSubviewToFront:view]; 328 | return self; 329 | }; 330 | } 331 | 332 | - (UIView *(^)(UIView *))sendSubviewToBack { 333 | return ^(UIView *view) { 334 | [self sendSubviewToBack:view]; 335 | return self; 336 | }; 337 | } 338 | 339 | - (UIView *(^)(UIGestureRecognizer *))addGesture { 340 | return ^(UIGestureRecognizer *gesture){ 341 | [self addGestureRecognizer:gesture]; 342 | return self; 343 | }; 344 | } 345 | 346 | - (UIView *(^)(UIGestureRecognizer *))removeGesture { 347 | return ^(UIGestureRecognizer *gesture){ 348 | [self removeGestureRecognizer:gesture]; 349 | return self; 350 | }; 351 | } 352 | @end 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/XRCategory/XRCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // XRCategory.h 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #ifndef XRCategory_h 10 | #define XRCategory_h 11 | #import "NSObject+XRCategory.h" 12 | #import "UIView+XRCategory.h" 13 | #import "UIControl+XRCategory.h" 14 | #import "UIButton+XRCategory.h" 15 | #import "UIImageView+XRCategory.h" 16 | #import "UILabel+XRCategory.h" 17 | #import "UIScrollView+XRCategory.h" 18 | #import "UITableView+XRCategory.h" 19 | #import "UITextField+XRCategory.h" 20 | #import "UITextView+XRCategory.h" 21 | #import "NSArray+XRCategory.h" 22 | #import "NSString+XRCategory.h" 23 | #import "NSDictionary+XRCategory.h" 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /XRCategoryDemo/XRCategoryDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // XRCategoryDemo 4 | // 5 | // Created by 肖睿 on 16/4/13. 6 | // Copyright © 2016年 肖睿. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------