2014资料整理--User Defined Runtime Attributes
来源:互联网 发布:如何将数据导入matlab 编辑:程序博客网 时间:2024/05/18 13:45
最近在xocde中发现了一个“User Defined Runtime Attributes”属性,之前没有用过,写下做个记录。如图:
在网上了一些资料感觉也没有说清,先说下我自己的理解:如果想扩展一个类方法,就要创建一个继承类。在需要引用它的xib中只需要设Custom Class,也就是新建的这个类,在“User Defined Runtime Attributes”下增加相应的key 和value就可以实现。之前的写法是在类文件中引用新建的类,在调用它的实现方法,传递相关的参数。现在这个属性可以省去了这一步。
下面是写的一个小例子,多谢朋友们的无私分享。
1、首先要建立一个类:MyImgView继承UIButton
MyImgView.h 内容如下:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface MyImgView : UIButton
@property (nonatomic,retain)NSNumber *cornerRadius;
@end
MyImgView.m 内容如下:#import "MyImgView.h"
#import <QuartzCore/CALayer.h>
@implementation MyImgView
@synthesize cornerRadius;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)drawRect:(CGRect)rect
{
[[selflayer]setCornerRadius:[cornerRadiusfloatValue]];
[[selflayer]setMasksToBounds:YES];
[[selflayer]setBackgroundColor:[selfgetColorFromRed:168.0Green:255.0Blue:168.0Alpha:1]];
NSLog(@"成功");
}
-(CGColorRef) getColorFromRed:(int)red Green:(int)green Blue:(int)blue Alpha:(int)alpha
{
CGFloat r = (CGFloat) red/255.0;
CGFloat g = (CGFloat) green/255.0;
CGFloat b = (CGFloat) blue/255.0;
CGFloat a = (CGFloat) alpha/255.0;
CGFloat components[4] = {r,g,b,a};
CGColorSpaceRef colorSpace =CGColorSpaceCreateDeviceRGB();
CGColorRef color = (CGColorRef)[(id)CGColorCreate(colorSpace, components)autorelease];
CGColorSpaceRelease(colorSpace);
return color;
}
@end
2.在ViewController.xib中拖放一个uibutton,并设置一个图片。
3、设置此按钮的“Custom Class”和“User Defined Runtime Attributes”,如下图:
运行就可以可以看到更改后的效果了。
使用时应当注意定义的变量应和xib中设置的key一样
有不对地方,希望大家帮忙指出来,3Q。
- 2014资料整理--User Defined Runtime Attributes
- User Defined Runtime Attributes
- User Defined Runtime Attributes
- User Defined Runtime Attributes
- User Defined Runtime Attributes
- User Defined Runtime Attributes
- User Defined Runtime Attributes
- 搜索看看? 搜索 User Defined Runtime Attributes
- xib中User Defined Runtime Attributes使用
- Expanding User-Defined Runtime Attributes in Xcode with Objective-C
- iOS User Defined Runtime Attributes to define the key path
- StoryBoard之User Defined Runtime Attributes的使用
- Pushing the Limits of User-Defined Runtime Attributes in Interface Builder
- User Defined Runtime Attributes在xib文件中给组件添加圆角
- iOS 在user defined runtime attributes(用户定义的运行时属性)改变UI
- 关于User Defined Runtime Attributes的使用,Xib定制view的边框、颜色etc
- [iOS]用Xib编辑视图时User Defined Runtime Attributes的使用
- oracle:System defined event attributes
- Android文件上传,关键代码
- UC --of 代码 一些笔记 与 学习
- JavaScript encodeURIComponent() 函数
- 处理jquery版本之间冲突
- Latent semantic analysis (LSA)
- 2014资料整理--User Defined Runtime Attributes
- 手动更新Eclipse的GWT plugin
- 模板方法
- 图片翻转效果
- 二维凸包convex hull之C++及OpenCV实现
- 什么情况下应当声明虚函数?纯虚函数声明
- Android渠道过多 对于游戏开发人员来说 就是灾难
- APNs 推送原理及问题
- Android界面布局