问题描述
我的问题很简单.在android中,我们可以将xml样式表与布局分开,以便可以在任何地方重复使用,并且可以轻松地进行UI设计更改进行编辑.
My question is a simple one. In android, we can separate xml stylesheet from layout so that it can be reuse everywhere and edited easily for UI design change.
在iOS xcode中也可以吗?如果可以的话(最好不要从控制器那里来)?需要图书馆吗?有什么好的图书馆?
Is it also possible in iOS xcode? if can how (prefer if not from controller)? need libraries? what are good libraries for that?
谢谢您的回答.
推荐答案
you can use UICategory class for UIView for that purpose. create different methods for set borders
, border colors
, pass bazier-paths
, corner
radius
and so many . this is just few of them. category is of UIView so you can use on buttons
,lables
,textview
,textedits
etc;
UIView + category.h
@interface UIView (category)
-(void)makeToRoundEdgeWithBorder:(CGFloat )borderwidth bordecolor:(UIColor *)color;
@end
UIView + category.m
@implementation UIView (category)
-(void)makeToRoundEdgeWithBorder:(CGFloat )borderwidth bordecolor:(UIColor *)color
{
NSLog(@"height %f width %f",CGRectGetHeight(self.frame),CGRectGetWidth(self.frame));
self.layer.cornerRadius=CGRectGetHeight(self.frame)/2;
self.layer.masksToBounds=YES;
self.layer.borderColor=[color CGColor];
self.layer.borderWidth=borderwidth;
}
@end
使用
[yourlable makeToRoundEdgeWithBorder:0.0f bordercolor:[UIColor clearColor] cornerRadius:8.0f];
[yourbutton makeToRoundEdgeWithBorder:0.0f bordercolor:[UIColor clearColor] cornerRadius:8.0f];
[yourTextview makeToRoundEdgeWithBorder:0.0f bordercolor:[UIColor clearColor] cornerRadius:8.0f];
[yourTextfield makeToRoundEdgeWithBorder:0.0f bordercolor:[UIColor clearColor] cornerRadius:8.0f];
这篇关于适用于iOS应用的有效UI样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!