[iOS]UIView+SimpleGet
来源:互联网 发布:软件管理 编辑:程序博客网 时间:2024/06/07 08:36
[iOS]UIView+SimpleGet
demo:http://download.csdn.net/download/u012881779/10050359
本文对UIView拓展是为了减少代码量,方便直接获取/改变frame的x、y、width、height、size、origin参数。
[ViewController]
#import "ViewController.h"#import "UIView+SimpleGet.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; for (int i = 0 ; i < 6 ; i ++) { UILabel *tempLab = [[UILabel alloc] init]; [tempLab setFrame:CGRectMake(0, 0, 100, 100)]; [tempLab setBackgroundColor:[UIColor blueColor]]; [tempLab setText:[NSString stringWithFormat:@"%d",i]]; [self.view addSubview:tempLab]; if (i == 0) { NSLog(@"x=%f",tempLab.x); tempLab.x = 110; } else if (i == 1) { NSLog(@"y=%f",tempLab.y); tempLab.y = 110; } else if (i == 2) { NSLog(@"w=%f",tempLab.w); tempLab.w = 90; } else if (i == 3) { [tempLab setBackgroundColor:[UIColor redColor]]; NSLog(@"h=%f",tempLab.h); tempLab.h = 90; } else if (i == 4) { NSLog(@"s=%@",NSStringFromCGSize(tempLab.s)); tempLab.s = CGSizeMake(80, 80); } else if (i == 5) { NSLog(@"o=%@",NSStringFromCGPoint(tempLab.o)); tempLab.o = CGPointMake(110, 110); } }}@end
[UIView+SimpleGet]
#import <UIKit/UIKit.h>@interface UIView (SimpleGet)@property (nonatomic, assign) CGFloat x; // x@property (nonatomic, assign) CGFloat y; // y@property (nonatomic, assign) CGFloat w; // width@property (nonatomic, assign) CGFloat h; // height@property (nonatomic, assign) CGSize s; // size@property (nonatomic, assign) CGPoint o; // origin@end#import "UIView+SimpleGet.h"@implementation UIView (SimpleGet)- (CGFloat)x { return self.frame.origin.x;}- (void)setX:(CGFloat)x { CGRect frame = self.frame; frame.origin.x = x; self.frame = frame;}- (CGFloat)y { return self.frame.origin.y;}- (void)setY:(CGFloat)y { CGRect frame = self.frame; frame.origin.y = y; self.frame = frame;}- (CGFloat)w { return self.frame.size.width;}- (void)setW:(CGFloat)w { CGRect frame = self.frame; frame.size.width = w; self.frame = frame;}- (CGFloat)h { return self.frame.size.height;}- (void)setH:(CGFloat)h { CGRect frame = self.frame; frame.size.height = h; self.frame = frame;}- (CGSize)s { return self.frame.size;}- (void)setS:(CGSize)s { CGRect frame = self.frame; frame.size = s; self.frame = frame;}- (CGPoint)o { return self.frame.origin;}- (void)setO:(CGPoint)o { CGRect frame = self.frame; frame.origin = o; self.frame = frame;}@end示意图:
阅读全文
0 0
- [iOS]UIView+SimpleGet
- IOS-UIView
- IOS UIView
- IOS UIView
- iOS UIView
- IOS UIView
- iOS UIView
- iOS UIView
- iOS UIView
- ios uiView run animate
- iOS的UIView
- ios UIView详解~~~~~
- iOS UIview传递参数
- IOS 应用UIView分析
- UIView-IOS开发
- iOS学习--UIView详解~~~~~
- IOS控件UIToolBar、UIView
- ios UIView 动画效果
- 倒计时 js
- iOS拨打电话
- 数据结构基础——指针及动态内存分配(malloc)
- JVM源码分析之FinalReference完全解读
- 函数闭包
- [iOS]UIView+SimpleGet
- hadoop大数据平台架构与实践
- &
- SparkSQL 简单测试
- 性能测试方案
- CAN波特率计算
- JMeter入门教程
- lowmemorykiller
- wordpress修改域名