iOS9新特性之UIStackView

一.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 方式也是可以的,就不再详细的说了,注意从属关系就好了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值