ios中NSObject分类
#import <Foundation/Foundation.h> #define BUNDLE_PATH_IMAGENAME(c) [[NSBundle mainBundle] pathForResource:c ofType:nil] @interface NSObject (UICateGory) @end @interface UILabel (ext) +(UILabel*)LabWithFrame:(CGRect)_rect text:(NSString*)aText textColor:(UIColor*)aColor textAlign:(NSTextAlignment)aAlign font:(UIFont*)aFont; @end #pragma mark ********** UIButton ************* @interface UIButton (ext) + (UIButton *)ButtonWithImageName:(NSString*)aImageName hImageName:(NSString*)aHImageName frame:(CGRect)aFrame title:(NSString *)aTitle titleColor:(UIColor *)aColor font:(UIFont *)aFont target:(id)aTarget action:(SEL)aAction; + (UIButton *)ButtonWithSystemImage:(CGRect)aFrame title:(NSString *)aTitle titleColor:(UIColor *)aColor font:(UIFont *)aFont target:(id)aTarget action:(SEL)aAction;
@end #pragma mark ********** UIImageView *************
@interface UIImageView (ext) + (UIImageView *)ImageViewImageName:(NSString*)aImageName frame:(CGRect)aRect; @end #pragma mark ********** UITableView *************
@interface UITableView (ext) + (UITableView *)TableViewWithFrame:(CGRect)frame style:(UITableViewStyle)style backgroundColor:(UIColor *)backgroundColor delegate:(id)delegate separatorStyle:(UITableViewCellSeparatorStyle)separatorStyle; @end #pragma mark ********** UITextField ************* @interface UITextField (ext) +(UITextField*)TextFieldWithFrame:(CGRect)_rect target:(id)target textColor:(UIColor*)aTextColor textAlign:(NSTextAlignment)aAlign placeHolder:(NSString*)holder clearMode:(UITextFieldViewMode)aViewMode returnKey:(UIReturnKeyType)returnKeyType keyBord:(UIKeyboardType)keyBord; @end #pragma mark ********** UIImage ************* @interface UIImage (ext) + (UIImage *) ImageWithColor: (UIColor *) color frame:(CGRect)aFrame;
@end =============== #import "NSObject+UICateGory.h" @implementation NSObject (UICateGory) @end @implementation UILabel (ext) +(UILabel*)LabWithFrame:(CGRect)_rect text:(NSString*)aText textColor:(UIColor*)aColor textAlign:(NSTextAlignment)aAlign font:(UIFont*)aFont{
UILabel *lab = [[[UILabel alloc] initWithFrame:_rect] autorelease];
lab.backgroundColor = [UIColor clearColor];
if ([aText length] > )
lab.text = aText;
if (aColor)
lab.textColor = aColor;
if(aAlign)
lab.textAlignment = aAlign;
if (aFont)
lab.font = aFont;
return lab;
}
@end @implementation UIButton (ext) + (UIButton *)ButtonWithImageName:(NSString*)aImageName hImageName:(NSString*)aHImageName frame:(CGRect)aFrame title:(NSString *)aTitle titleColor:(UIColor *)aColor font:(UIFont *)aFont target:(id)aTarget action:(SEL)aAction{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = aFrame;
if ([aImageName length] > ) {
UIImage *bgImg = [UIImage imageWithContentsOfFile:BUNDLE_PATH_IMAGENAME(aImageName)];
if ([bgImg respondsToSelector:@selector(resizableImageWithCapInsets:)]) {
[button setBackgroundImage:[bgImg resizableImageWithCapInsets:UIEdgeInsetsMake(bgImg.size.height/, bgImg.size.width/, bgImg.size.height/, bgImg.size.width/)] forState:UIControlStateNormal];
}else {
[button setBackgroundImage:[bgImg stretchableImageWithLeftCapWidth:bgImg.size.width/ topCapHeight:bgImg.size.height/] forState:UIControlStateNormal];
}
}
if ([aHImageName length] > )
{
UIImage *bgImg = [UIImage imageWithContentsOfFile:BUNDLE_PATH_IMAGENAME(aHImageName)]; if ([bgImg respondsToSelector:@selector(resizableImageWithCapInsets:)]) {
[button setBackgroundImage:[bgImg resizableImageWithCapInsets:UIEdgeInsetsMake(bgImg.size.height/, bgImg.size.width/, bgImg.size.height/, bgImg.size.width/)] forState:UIControlStateHighlighted];
}else {
[button setBackgroundImage:[bgImg stretchableImageWithLeftCapWidth:bgImg.size.width/ topCapHeight:bgImg.size.height/] forState:UIControlStateHighlighted];
}
}
if ([aTitle length] > )
[button setTitle:aTitle forState:UIControlStateNormal];
if (aColor)
[button setTitleColor:aColor forState:UIControlStateNormal];
if (aFont)
button.titleLabel.font = aFont;
[button addTarget:aTarget action:aAction forControlEvents:UIControlEventTouchUpInside]; return button;
}
+ (UIButton *)ButtonWithSystemImage:(CGRect)aFrame title:(NSString *)aTitle titleColor:(UIColor *)aColor font:(UIFont *)aFont target:(id)aTarget action:(SEL)aAction{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = aFrame;
if ([aTitle length] > )
[button setTitle:aTitle forState:UIControlStateNormal];
if (aColor)
[button setTitleColor:aColor forState:UIControlStateNormal];
if (aFont)
button.titleLabel.font = aFont;
[button addTarget:aTarget action:aAction forControlEvents:UIControlEventTouchUpInside]; return button;
} @end @implementation UIImageView (ext) + (UIImageView *)ImageViewImageName:(NSString*)aImageName frame:(CGRect)aRect{
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:aRect] autorelease];
imageView.userInteractionEnabled = YES;
UIImage *aImage = [UIImage imageWithContentsOfFile:BUNDLE_PATH_IMAGENAME(aImageName)];
if ([aImage respondsToSelector:@selector(resizableImageWithCapInsets:)]) {
imageView.image = [aImage resizableImageWithCapInsets:UIEdgeInsetsMake(aImage.size.height/, aImage.size.width/, aImage.size.height/, aImage.size.width/)];
} else {
imageView.image = [aImage stretchableImageWithLeftCapWidth:aImage.size.width/ topCapHeight:aImage.size.height/];
}
return imageView;
} @end @implementation UITableView (ext) + (UITableView *)TableViewWithFrame:(CGRect)frame style:(UITableViewStyle)style backgroundColor:(UIColor *)backgroundColor delegate:(id)delegate separatorStyle:(UITableViewCellSeparatorStyle)separatorStyle { UITableView *tableView = [[[UITableView alloc] initWithFrame:frame style:style] autorelease];
[tableView setBackgroundColor:backgroundColor];
[tableView setDelegate:delegate];
[tableView setDataSource:delegate];
[tableView setSeparatorStyle:separatorStyle]; return tableView;
} @end @implementation UITextField (ext) +(UITextField*)TextFieldWithFrame:(CGRect)_rect target:(id)target textColor:(UIColor*)aTextColor textAlign:(NSTextAlignment)aAlign placeHolder:(NSString*)holder clearMode:(UITextFieldViewMode)aViewMode returnKey:(UIReturnKeyType)returnKeyType keyBord:(UIKeyboardType)keyBord{
UITextField *textField = [[[UITextField alloc] initWithFrame:_rect] autorelease];
textField.backgroundColor = [UIColor clearColor];
textField.delegate = target;
textField.returnKeyType = returnKeyType;
textField.keyboardType = keyBord;
if (aAlign)
textField.textAlignment = aAlign;
if (aTextColor)
textField.textColor = aTextColor;
if (aViewMode)
textField.clearButtonMode = aViewMode;
if ([holder length] > )
textField.placeholder = holder;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; return textField;
} @end #pragma mark ********** UIImage ************* @implementation UIImage (ext) + (UIImage *) ImageWithColor: (UIColor *) color frame:(CGRect)aFrame
{
aFrame = CGRectMake(, , aFrame.size.width, aFrame.size.height);
UIGraphicsBeginImageContext(aFrame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, aFrame); UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
@end
ios中NSObject分类的更多相关文章
- ios中NSObject分类(2)
#import <Foundation/Foundation.h> UIColor * rgb(int r, int g, int b); UIColor * rgbA(int r, in ...
- IOS中把字符串加密/IOS中怎么样MD5加密/IOS中NSString分类的实现
看完过后,你会学到: 1学习IOS开发中的分类实现, 2以及类方法的书写, 3以及字符串的MD5加密/解密. ---------------------------wolfhous---------- ...
- iOS中的分类(category)和类扩展(extension)
今天在研究swift的时候看到了分类和扩展.这是两个十分重要有用的功能,但是之前用的不多,没有深入了解过,在今天就从头理一遍. 一.分类(Category): 概念: 分类(Category)是OC中 ...
- iOS中的分类和扩展
一.什么是分类? 概念:分类(Category)是OC中的特有语法,它是表示一个指向分类的结构体指针.根据下面源码组成可以看到它没有属性列表,原则上是不能添加成员变量(其实可以借助运行时功能,进行关联 ...
- 转iOS中delegate、protocol的关系
iOS中delegate.protocol的关系 分类: iOS Development2014-02-12 10:47 277人阅读 评论(0) 收藏 举报 delegateiosprocotolc ...
- iOS仿京东分类菜单之UICollectionView内容
在上<iOS仿京东分类菜单实例实现>已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果,本文涉及到的主要是UICollectionView的知识内容,左边列 ...
- iOS中的动画
iOS中的动画 Core Animation Core Animation是一组非常强大的动画处理API,使用它能做出非常绚丽的动画效果,而且往往是事半功倍,使用它需要添加QuartzCore .fr ...
- iOS中关于KVC与KVO知识点
iOS中关于KVC与KVO知识点 iOS中关于KVC与KVO知识点 一.简介 KVC/KVO是观察者模式的一种实现,在Cocoa中是以被万物之源NSObject类实现的NSKeyValueCodin ...
- ios中关于delegate(委托)的使用心得
ios中关于delegate(委托)的使用心得 分类: iOS开发2012-05-15 10:54 34793人阅读 评论(9) 收藏 举报 iosuiviewtimerinterfaceprinti ...
随机推荐
- Sequence在Oracle中的使用
Oracle中,当需要建立一个自增字段时,需要用到sequence.sequence也可以在mysql中使用,但是有些差别,日后再补充,先把oracle中sequence的基本使用总结一下,方便日后查 ...
- springboot 项目mybatis plus 设置 jdbcTypeForNull (oracle数据库需配置JdbcType.NULL, 默认是Other)
方法1: application.yml mybatis-plus: configuration: jdbc-type-for-null: 'null' #注意:单引号 方法2: 查看mp-start ...
- DNS预解析dns-prefetch提升页面载入速度优化前端性能
当浏览器请求一个URL的时候,通过firebug我们可以发现大概有以下几个过程:阻挡.域名解析.建立连接.发送请求.等待响应.接收数据.后面四个跟用户的网络情况和你的服务器处理速度有关,本文重点说说前 ...
- 【大数据】基于Hadoop的HBase的安装(转)
https://note.youdao.com/share/?id=c27485373a08517f7ad2e7ec901cd8d5&type=note#/ 安装前先确认HBse和Hadoop ...
- 如何三招帮你排查Linux中的硬件问题
下列贴士帮助你更快速更轻松地为Linux中的硬件排查故障.许多不同的因素可能导致Linux硬件出现问题:在你开始尝试诊断之前,了解最常见的问题以及最有可能找到原因的环节是明智之举. Linux服务器在 ...
- Linux系统中查找、删除重复文件,释放磁盘空间。
在Linux系操作系统中查找并删除重复文件的方法的确有很多,不过这里介绍的是一款非常简单实用的软件FSlint.FSlint是一个重复文件查找工具,可以使用它来清除不必要的重复文件,笔者经常使用它来释 ...
- 转: xshell远程连接自动断开的问题解决办法
转:http://blog.csdn.net/haijiaoqihao20160106/article/details/50623431 2.客户端的配置 Keep Alive修改.我的xshell的 ...
- ACM~排列组合&&hdu例子
排列组合是数学中的一个分支.在计算机编程方面也有非常多的应用,主要有排列公式和组合公式.错排公式.母函数.Catalan Number(卡特兰数)等. 一.有关组合数学的公式 1.排列公式 P(n ...
- Mongoose Connection best practice
There is often quite a lot of confusion about how best to set up a database connection with Mongoose ...
- Authentication and Authorization in ASP.NET Web API
You've created a web API, but now you want to control access to it. In this series of articles, we ...