#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. MFC中插入符的生成

    响应WM_CREATE消息的代码如下: int CTextView::OnCreate(LPCREATESTRUCT lpCreateStruct) { ) ; // 插入符在窗口重绘的过程中不会消失 ...

  2. 中文分词 coreseek安装笔记

    #!/bin/bash # create by lhb # date 2013-11-26 # coreseek install script apt-get install make gcc g++ ...

  3. 使用新版SDK不想跳转微博客户端能否直接发送微博分享?

    如题啊如题! 新版本中没有StatusesAPI?????

  4. ES8新特性——ES8 was Released and here are its Main New Features

    原文: https://hackernoon.com/es8-was-released-and-here-are-its-main-new-features-ee9c394adf66 -------- ...

  5. Spring(十二):IOC容器中Bean的生命周期方法

    IOC容器中Bean的生命周期方法 1)Spring IOC容器可以管理Bean的声明周期,Spring允许在Bean生命周期的特定点执行定制的任务. 2)Spring IOC容器对Bean的生命周期 ...

  6. java多线程分块上传并支持断点续传最新修正完整版本[转]

    package com.test; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.Fi ...

  7. C#.NET常见问题(FAQ)-如何让Listbox支持多选

    把SelectionMode改成MultiExtended   更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com/acetaohai123   我的在线 ...

  8. Discuz常见小问题-_如何修改网站LOGO

    1 界面-风格管理,点击编辑 2 默认的LOGO图片叫做logo.png,存放在X:\PHPNow\htdocs\Discuz\upload\static\image\common文件夹下面,其中X是 ...

  9. Linux Centos7中MySql安装

    (1)     安装Mysql5.7: 执行命令:rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-co ...

  10. TP - 001