#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. C#中转义字符[转]

    https://www.cnblogs.com/muran/p/3174865.html 编程中很多细节问题我们都要十分的注意,要不一个小小的字母错误就能引起程序的无法运行. C#中转义字符分2中,一 ...

  2. Vue上传图片预览组件

    父组件: <template> <div> <h4>基于Vue.2X的html5上传图片组件</h4> <div style="widt ...

  3. 基于Deep Learning的中文分词尝试

    http://h2ex.com/1282 现有分词介绍 自然语言处理(NLP,Natural Language Processing)是一个信息时代最重要的技术之一,简单来讲,就是让计算机能够理解人类 ...

  4. Linux命令行极简教程

    1.命令行真的好吗 程序员的使命 维基百科的解释: 命令行界面(英语:command-line interface,缩写:CLI)是在图形用户界面得到普及之前使用最为广泛的用户界面,它通常不支持鼠标, ...

  5. go-ethereum

    如果要深入了解go-ethereum项目的实现与机制,看源代码是必不可少的.今天这篇博客就简单介绍一下如何在本地搭建项目的开发环境. GO语言环境搭建 以win8为例,访问地址https://gola ...

  6. GPUImage API文档之GPUImageFramebufferCache类

    GPUImageFramebufferCache类负责管理GPUImageFramebuffer对象,是一个GPUImageFramebuffer对象的缓存. 方法 - (GPUImageFrameb ...

  7. linux免密码登录

    ssh-copy-id 命令 可以把本地主机的公钥复制到远程主机的authorized_keys文件上,ssh-copy-id命令也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh ...

  8. 夏天过去了, 姥爷推荐几套来自smashingmagzine的超棒秋天主题壁纸

    夏天就要过去啦, 特别在这个时候,分享几套来自smashingmagazine的秋天主题壁纸,如果,你也喜欢的话, 可以去下载哈~ 更多尺寸壁纸下载 日历版本: 320×480, 640×480, 8 ...

  9. 使用jstl报http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar错误

    今天创建了一个maven项目,想使用jstl报http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the ...

  10. CMUSphinx Learn - Basic concepts of speech

    Basic concepts of speech Speech is a complex phenomenon. People rarely understand how is it produced ...