#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分类的更多相关文章

  1. ios中NSObject分类(2)

    #import <Foundation/Foundation.h> UIColor * rgb(int r, int g, int b); UIColor * rgbA(int r, in ...

  2. IOS中把字符串加密/IOS中怎么样MD5加密/IOS中NSString分类的实现

    看完过后,你会学到: 1学习IOS开发中的分类实现, 2以及类方法的书写, 3以及字符串的MD5加密/解密. ---------------------------wolfhous---------- ...

  3. iOS中的分类(category)和类扩展(extension)

    今天在研究swift的时候看到了分类和扩展.这是两个十分重要有用的功能,但是之前用的不多,没有深入了解过,在今天就从头理一遍. 一.分类(Category): 概念: 分类(Category)是OC中 ...

  4. iOS中的分类和扩展

    一.什么是分类? 概念:分类(Category)是OC中的特有语法,它是表示一个指向分类的结构体指针.根据下面源码组成可以看到它没有属性列表,原则上是不能添加成员变量(其实可以借助运行时功能,进行关联 ...

  5. 转iOS中delegate、protocol的关系

    iOS中delegate.protocol的关系 分类: iOS Development2014-02-12 10:47 277人阅读 评论(0) 收藏 举报 delegateiosprocotolc ...

  6. iOS仿京东分类菜单之UICollectionView内容

    在上<iOS仿京东分类菜单实例实现>已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果,本文涉及到的主要是UICollectionView的知识内容,左边列 ...

  7. iOS中的动画

    iOS中的动画 Core Animation Core Animation是一组非常强大的动画处理API,使用它能做出非常绚丽的动画效果,而且往往是事半功倍,使用它需要添加QuartzCore .fr ...

  8. iOS中关于KVC与KVO知识点

    iOS中关于KVC与KVO知识点 iOS中关于KVC与KVO知识点  一.简介 KVC/KVO是观察者模式的一种实现,在Cocoa中是以被万物之源NSObject类实现的NSKeyValueCodin ...

  9. ios中关于delegate(委托)的使用心得

    ios中关于delegate(委托)的使用心得 分类: iOS开发2012-05-15 10:54 34793人阅读 评论(9) 收藏 举报 iosuiviewtimerinterfaceprinti ...

随机推荐

  1. go语言之进阶篇定时器重置

    1.定时器重置 示例: package main import ( "fmt" "time" ) func main() { timer := time.New ...

  2. iOS开发-CocoaPods实战

    CocoaPods 是开发 OS X 和 iOS 应用程序的第三方库的依赖管理工具,如果是正常的开发不需要使用的第三方的代码,CocoaPods是不需要的,但是从实际情况上,为了提高开发效率,Coco ...

  3. Java Base64加密解密

    使用Apache commons codec 类Base64 maven依赖 <dependency> <groupId>commons-codec</groupId&g ...

  4. LTR之RankSvm

    两种对比: 1.深度学习CNN提特征+RankSVM 之前的博客:http://www.cnblogs.com/bentuwuying/p/6681943.html中简单介绍了Learning to ...

  5. 解决webstom failed to change read-only files

    我百思不得其解的是,为何我的文件不让我更改,变成了只读模式,后来我仔细回忆了一下,原来是因为我使用了root权限,来安装thinkjs之后,webstom没有root权限,所以我使用root,在终端敲 ...

  6. GPUImage API文档之GPUImageInput协议

    GPUImageInput协议主要包含一些输入需要渲染目标的操作. - (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)t ...

  7. AT&T汇编和Intel汇编语法主要区别

    AT&T使用$表示立即操作数,而Intel的立即操作数是不需要界定的.因此,使用AT&T语法引用十进制值4时,使用$4,使用Intel语法时只需使用4.   AT&T在寄存器名 ...

  8. JS base64加解密解决传输的url各种编码问题

    网上拷贝的,废话少说,直接上代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  9. hibernate调用mysql存储过程

    在mysql中创建两个存储过程,如下: 1.根据id查找某条数据: )) begin select * from emp where empId=id; end; 2.根据id查找某个字段,并返回 ) ...

  10. SpringBoot 分页处理

    开始主要是要使用已经设计好的数据库 -- ---------------------------------------------------- -- 用户 -- ----------------- ...