今天视图添加东西

今天视图添加东西

先创建一个ios工程项

  1. 目,这个大家都会不用多说,直接说今天视图。
  2. 点击菜单File –> new –> target…

这里写图片描述

这里写图片描述

之后你的工程里就会多出一个文件夹 里有三个文件
这里写图片描述

这里写图片描述

刚创建的时候就有一个项,不过那个我给删除了,是一个storyboard文件,这个看个人习惯。
这里写图片描述

  1. 看到这个后就算你创建成功了,接下来就是大家最想看到的代码阶段了 Go go go 》》》》

- (void)viewDidLoad {

        [super viewDidLoad];

        self.preferredContentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 180);
        self.view.backgroundColor = [UIColor clearColor];

        [self initWithUI];
}

- (void)viewWillAppear:(BOOL)animated {

        [super viewWillAppear:animated];
        self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeExpanded;
}


- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {

        if (activeDisplayMode == NCWidgetDisplayModeCompact) {
                self.preferredContentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 180);
        } else {
                self.preferredContentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 190);
        }
}


- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets{

        return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];
}

- (void)initWithUI {

      // 这里就是大家平时写的 UI 想要做什么样的 可以在这里尽情的发挥哦~    
        float x = 20;
        NSArray *rowArr1 = @[@"WIFI",@"数据",@"微博",@"QQ",@"微信"];
        for (int i = 0; i < rowArr1.count; i++) {

                UIButton *btn1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
                [btn1 setTitle:rowArr1[i] forState:(UIControlStateNormal)];
                btn1.frame = CGRectMake(x + 55 * i, 10, 64, 40);
                btn1.backgroundColor = [UIColor clearColor];
                btn1.titleLabel.font = i % 2 == 0 ? [UIFont boldSystemFontOfSize:15] : [UIFont systemFontOfSize:14];
                [btn1 addTarget:self action:@selector(skip:)

               forControlEvents:(UIControlEventTouchUpInside)];
                btn1.tag = 601 + i;
                [self.view addSubview:btn1];
    }

    NSArray *rowArr2 = @[@"短信",@"设置",@"相册",@"Safari",@"Store"];
    for (int i = 0; i < rowArr2.count; i++) {

            UIButton *btn1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
            [btn1 setTitle:rowArr2[i] forState:(UIControlStateNormal)];
            btn1.frame = CGRectMake(x + 55 * i, 50, 54, 40);
            btn1.backgroundColor = [UIColor clearColor];
            btn1.titleLabel.font = i % 2 == 0 ? [UIFont boldSystemFontOfSize:15] : [UIFont systemFontOfSize:14];

            [btn1 addTarget:self action:@selector(skip:)
           forControlEvents:(UIControlEventTouchUpInside)];
            btn1.tag = 606 + i;
            [self.view addSubview:btn1];
    }

}

写完运行满怀信心的去下拉看了一下,很失望什么也没有,不知道哪里写错了呢。
这里写图片描述

去编辑一下

这里写图片描述

这里写图片描述

好了到这里就大功告成了,可以打包给你朋友们安装试试了哦。
希望能给大家带来种种方便哦~​
大家有什么好的想法尽情骚扰哦~ 加油!​

总结:6s模拟器每次运行完之后要清空一下,要不然会报错了的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值