一.UIStackView的属性,如图所示,有几种
1.Axis:Vertical 和 Horizontal 两种排列方式
2.Alignment(对齐方式): Fill Top Center Bottom
3.Distribution:Fill Fill Equally Fill Proportionally Equal Spacing Equal Centering(由于并不常见,所以就不过多阐述了)
4.Spacing(间隔):
二.纯代码设计uistackview(如图所示界面)
1.首先创建一个工程,然后在ViewController.h文件中写代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 整体UIstackview
UIStackView *stackview=[[UIStackView alloc]initWithFrame:CGRectMake(50, 50, 200, 50)];
stackview.axis =UILayoutConstraintAxisHorizontal;//水平方向的属性
//父UIstackview控件的两块之间的间隔
stackview.spacing=10;
[self.view addSubview:stackview];//将其添加到uiview上
//图片的添加
UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
imageview.image=[UIImage imageNamed:@"right2.png"];
[stackview addArrangedSubview:imageview];//将UIImageView添加到UIStackView上
//子stackview
UIStackView *stackviewsub=[[UIStackView alloc]initWithFrame:CGRectMake(0,0,150,50)];
stackviewsub.axis=UILayoutConstraintAxisVertical;//垂直方向的属性
stackviewsub.alignment=UIStackViewAlignmentLeading;//左对齐
UIImageView *imageview2=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,38,10)];
imageview2.image=[UIImage imageNamed:@"right1.png"];
UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(0,0,88,10)];
lable.text=@"人均¥18 ";
lable.font=[UIFont systemFontOfSize:17.0];//设置字体大小
UILabel *lable1=[[UILabel alloc]initWithFrame:CGRectMake(0,0,150,10)];
lable1.text=@"口味21环境21价格18";
lable1.font=[UIFont systemFontOfSize:8.0];
//将三个字控件添加到stackviewsub上
[stackviewsub addArrangedSubview:imageview2];
[stackviewsub addArrangedSubview:lable];
[stackviewsub addArrangedSubview:lable1];
//将stackviewsub控件添加到stackview上
[stackview addArrangedSubview:stackviewsub];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
2.Assets.xcassets中插入图片
再运行就可以喽!
三.xib 方式也是可以的,就不再详细的说了,注意从属关系就好了。