iOS UIView常見屬性方法小結(jié)
下面通過實(shí)例代碼給大家詳細(xì)介紹了iOS UIView常見屬性方法,具體代碼如下所示:
UIView : UIResponder /** 通過一個(gè)frame來初始化一個(gè)UI控件 */ - (id)initWithFrame:(CGRect)frame; // YES:能夠跟用戶進(jìn)行交互 @property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default is YES // 控件的一個(gè)標(biāo)記(父控件可以通過tag找到對應(yīng)的子控件) @property(nonatomic) NSInteger tag; // default is 0 // 圖層(可以用來設(shè)置圓角效果\陰影效果) @property(nonatomic,readonly,retain) CALayer *layer; @interface UIView(UIViewGeometry) // 位置和尺寸(以父控件的左上角為坐標(biāo)原點(diǎn)(0, 0)) @property(nonatomic) CGRect frame; // 位置和尺寸(以自己的左上角為坐標(biāo)原點(diǎn)(0, 0)) @property(nonatomic) CGRect bounds; // 中點(diǎn)(以父控件的左上角為坐標(biāo)原點(diǎn)(0, 0)) @property(nonatomic) CGPoint center; // 形變屬性(平移\縮放\旋轉(zhuǎn)) @property(nonatomic) CGAffineTransform transform; // default is CGAffineTransformIdentity // YES:支持多點(diǎn)觸摸 @property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled; // default is NO @end @interface UIView(UIViewHierarchy) // 父控件 @property(nonatomic,readonly) UIView *superview; // 子控件(新添加的控件默認(rèn)都在subviews數(shù)組的后面, 新添加的控件默認(rèn)都顯示在最上面\最頂部) @property(nonatomic,readonly,copy) NSArray *subviews; // 獲得當(dāng)前控件所在的window @property(nonatomic,readonly) UIWindow *window; // 從父控件中移除一個(gè)控件 - (void)removeFromSuperview; // 添加一個(gè)子控件(可以將子控件插入到subviews數(shù)組中index這個(gè)位置) - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; // 交換subviews數(shù)組中所存放子控件的位置 - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2; // 添加一個(gè)子控件(新添加的控件默認(rèn)都在subviews數(shù)組的后面, 新添加的控件默認(rèn)都顯示在最上面\最頂部) - (void)addSubview:(UIView *)view; // 添加一個(gè)子控件view(被擋在siblingSubview的下面) - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview; // 添加一個(gè)子控件view(蓋在siblingSubview的上面) - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview; // 將某個(gè)子控件拉到最上面(最頂部)來顯示 - (void)bringSubviewToFront:(UIView *)view; // 將某個(gè)子控件拉到最下面(最底部)來顯示 - (void)sendSubviewToBack:(UIView *)view; /**系統(tǒng)自動(dòng)調(diào)用(留給子類去實(shí)現(xiàn))**/ - (void)didAddSubview:(UIView *)subview; - (void)willRemoveSubview:(UIView *)subview; - (void)willMoveToSuperview:(UIView *)newSuperview; - (void)didMoveToSuperview; - (void)willMoveToWindow:(UIWindow *)newWindow; - (void)didMoveToWindow; /**系統(tǒng)自動(dòng)調(diào)用**/ // 是不是view的子控件或者子控件的子控件(是否為view的后代) - (BOOL)isDescendantOfView:(UIView *)view; // returns YES for self. // 通過tag獲得對應(yīng)的子控件(也可以或者子控件的子控件) - (UIView *)viewWithTag:(NSInteger)tag; // recursive search. includes self /**系統(tǒng)自動(dòng)調(diào)用(留給子類去實(shí)現(xiàn))**/ // 控件的frame發(fā)生改變的時(shí)候就會(huì)調(diào)用,一般在這里重寫布局子控件的位置和尺寸 // 重寫了這個(gè)寫方法后,一定調(diào)用[super layoutSubviews]; - (void)layoutSubviews; @end @interface UIView(UIViewRendering) // YES : 超出控件邊框范圍的內(nèi)容都剪掉 @property(nonatomic) BOOL clipsToBounds; // 背景色 @property(nonatomic,copy) UIColor *backgroundColor; // default is nil // 透明度(0.0~1.0) @property(nonatomic) CGFloat alpha; // default is 1.0 // YES:不透明 NO:透明 @property(nonatomic,getter=isOpaque) BOOL opaque; // default is YES // YES : 隱藏 NO : 顯示 @property(nonatomic,getter=isHidden) BOOL hidden; // 內(nèi)容模式 @property(nonatomic) UIViewContentMode contentMode; // default is UIViewContentModeScaleToFill @end //動(dòng)畫 @interface UIView(UIViewAnimationWithBlocks) + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations; + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion; @end
以上所述是小編給大家介紹的iOS UIView常見屬性方法小結(jié),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- iOS為UIView設(shè)置陰影效果
- iOS應(yīng)用開發(fā)中UIView添加邊框顏色及設(shè)置圓角邊框的方法
- 詳解iOS中UIView的layoutSubviews子視圖布局方法使用
- 詳解iOS開發(fā)中的轉(zhuǎn)場動(dòng)畫和組動(dòng)畫以及UIView封裝動(dòng)畫
- 詳解iOS App開發(fā)中UIViewController的loadView方法使用
- iOS動(dòng)畫-定時(shí)對UIView進(jìn)行翻轉(zhuǎn)和抖動(dòng)的方法
- IOS自定義UIView
- IOS UIView的生命周期的實(shí)例詳解
- IOS設(shè)置UIView的邊框?yàn)閳A角詳解及實(shí)例
- iOS布局渲染之UIView方法的調(diào)用時(shí)機(jī)詳解
相關(guān)文章
iOS狀態(tài)欄frame計(jì)算問題的實(shí)現(xiàn)
這篇文章主要介紹了iOS狀態(tài)欄frame計(jì)算問題的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-06-06iOS swift 總結(jié)NavigationController出現(xiàn)問題及解決方法
這篇文章主要介紹了iOS swift 總結(jié)NavigationController出現(xiàn)問題及解決方法的相關(guān)資料,需要的朋友可以參考下2016-12-12IOS 開發(fā)之實(shí)現(xiàn)取消tableView返回時(shí)cell選中的問題
這篇文章主要介紹了IOS 開發(fā)之實(shí)現(xiàn)取消tableView返回時(shí)cell選中的問題的相關(guān)資料,希望通過本文能實(shí)現(xiàn)大家想要的功能,需要的朋友可以參考下2017-09-09IOS UI學(xué)習(xí)教程之設(shè)置UITextField各種屬性
這篇文章主要為大家詳細(xì)介紹了IOS UI學(xué)習(xí)教程之設(shè)置UITextField各種屬性,感興趣的小伙伴們可以參考一下2016-03-03iOS自動(dòng)移除KVO觀察者的實(shí)現(xiàn)方法
在 Apple 的應(yīng)用開發(fā)里 KVO 提供了一個(gè)途徑,使對象(觀察者)能夠觀察其他對象(被觀察者)的屬性,當(dāng)被觀察者的屬性發(fā)生變化時(shí),觀察者就會(huì)被告知該變化。下面這篇文章主要給大家介紹了關(guān)于iOS如何自動(dòng)移除KVO觀察者的實(shí)現(xiàn)方法,需要的朋友可以參考下。2017-12-12詳解在iOS11下app圖標(biāo)變空白的問題解決方法
本篇文章主要介紹了詳解在iOS11下app圖標(biāo)變空白的問題解決方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12