232
技術社區[雲棲]
UIView擴展,很實用
// // UIView+Ext.h // HomeLinkProject // // Created by huangyibiao on 14-6-1. // Copyright (c) 2014年 huangyibiao. All rights reserved. // #import <UIKit/UIKit.h> ///< UIView的擴展類 ///< @author huangyibiao @interface UIView (Ext) /** * @brief Shortcut for frame.origin.x. * Sets frame.origin.x = originX */ @property (nonatomic) CGFloat originX; /** * @brief Shortcut for frame.origin.y * Sets frame.origin.y = originY */ @property (nonatomic) CGFloat originY; /** * @brief Shortcut for frame.origin.x + frame.size.width * Sets frame.origin.x = rightX - frame.size.width */ @property (nonatomic) CGFloat rightX; /** * @brief Shortcut for frame.origin.y + frame.size.height * Sets frame.origin.y = bottomY - frame.size.height */ @property (nonatomic) CGFloat bottomY; /** * @brief Shortcut for frame.size.width * Sets frame.size.width = width */ @property (nonatomic) CGFloat width; /** * @brief Shortcut for frame.size.height * Sets frame.size.height = height */ @property (nonatomic) CGFloat height; /** * @brief Shortcut for center.x * Sets center.x = centerX */ @property (nonatomic) CGFloat centerX; /** * @brief Shortcut for center.y * Sets center.y = centerY */ @property (nonatomic) CGFloat centerY; /** * @brief Shortcut for frame.origin */ @property (nonatomic) CGPoint origin; /** * @brief Shortcut for frame.size */ @property (nonatomic) CGSize size; ///< 移除此view上的所有子視圖 - (void)removeAllSubviews; @end
//
// UIView+Ext.m
// HomeLinkProject
//
// Created by huangyibiao on 14-6-1.
// Copyright (c) 2014年 huangyibiao. All rights reserved.
//
#import "UIView+Ext.h"
@implementation UIView (Ext)
- (CGFloat)originX {
return self.frame.origin.x;
}
- (void)setOriginX:(CGFloat)originX {
CGRect frame = self.frame;
frame.origin.x = originX;
self.frame = frame;
return;
}
- (CGFloat)originY {
return self.frame.origin.y;
}
- (void)setOriginY:(CGFloat)originY {
CGRect frame = self.frame;
frame.origin.y = originY;
self.frame = frame;
return;
}
- (CGFloat)rightX {
return [self originX] + [self width];
}
- (void)setRightX:(CGFloat)rightX {
CGRect frame = self.frame;
frame.origin.x = rightX - [self width];
self.frame = frame;
return;
}
- (CGFloat)bottomY {
return [self originY] + [self height];
}
- (void)setBottomY:(CGFloat)bottomY {
CGRect frame = self.frame;
frame.origin.y = bottomY - [self height];
self.frame = frame;
return;
}
- (CGFloat)centerX {
return self.center.x;
}
- (void)setCenterX:(CGFloat)centerX {
self.center = CGPointMake(centerX, self.center.y);
return;
}
- (CGFloat)centerY {
return self.center.y;
}
- (void)setCenterY:(CGFloat)centerY {
self.center = CGPointMake(self.center.x, centerY);
return;
}
- (CGFloat)width {
return self.frame.size.width;
}
- (void)setWidth:(CGFloat)width {
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
return;
}
- (CGFloat)height {
return self.frame.size.height;
}
- (void)setHeight:(CGFloat)height {
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
return;
}
- (CGPoint)origin {
return self.frame.origin;
}
- (void)setOrigin:(CGPoint)origin {
CGRect frame = self.frame;
frame.origin = origin;
self.frame = frame;
return;
}
- (CGSize)size {
return self.frame.size;
}
- (void)setSize:(CGSize)size {
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
return;
}
///< 移除此view上的所有子視圖
- (void)removeAllSubviews {
for (UIView *view in self.subviews) {
[view removeFromSuperview];
}
return;
}
@end
最後更新:2017-04-03 05:39:42
上一篇:
js遍曆 子節點 子元素
下一篇:
性能測試服務(PTS)公測
大數據分析技術深度發展 智能交通呈現三大趨勢
Work like Alibaba——你也可以,像阿裏巴巴一樣工作
Jquery倒數計時按鈕—setTimeout
ubuntu下QT4開發環境的搭建
Maven學習八之pom.xml簡介以及客戶端下載包的流程
java 商戶 多用戶管理係統 SSM springmvc 項目源碼 庫存 進銷存
HTAP數據庫 PostgreSQL 場景與性能測試之 20 - (OLAP) 用戶畫像圈人場景 - 多個字段任意組合條件篩選與透視
如何等待java線程池中所有任務完成
從火爆到死寂,互聯網醫療迷霧重重,為何走不出盈利漩渦?
node實現簡單的群體聊天工具