今天视图添加东西
先创建一个ios工程项
- 目,这个大家都会不用多说,直接说今天视图。
- 点击菜单File –> new –> target…
之后你的工程里就会多出一个文件夹 里有三个文件
刚创建的时候就有一个项,不过那个我给删除了,是一个storyboard文件,这个看个人习惯。
- 看到这个后就算你创建成功了,接下来就是大家最想看到的代码阶段了 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模拟器每次运行完之后要清空一下,要不然会报错了的。