当前位置:网站首页>[Objective-C] dynamically create controls
[Objective-C] dynamically create controls
2022-06-11 10:15:00 【Back end coder】
Create controls dynamically
//
// ViewController.m
// MediaIOS
//
// Created by Inke219223m on 2022/5/23.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
// Dynamic controls are created inside
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// Create button
//UIButton *ubOne = [[UIButton alloc] init];// Default
// Button type
//UIButton *ubOne = [UIButton buttonWithType:UIButtonTypeContactAdd];
UIButton *ubOne = [UIButton buttonWithType:UIButtonTypeCustom];
// Set button text Default state
[ubOne setTitle:@" Click on me " forState:UIControlStateNormal];
// The highlighted
[ubOne setTitle:@" Back end coder " forState:UIControlStateHighlighted];
UIImage *uimg = [UIImage imageNamed:@" Hamburger "];
UIImage *uimg2 = [UIImage imageNamed:@" French fries "];
// Set default state picture
[ubOne setBackgroundImage:uimg forState:UIControlStateNormal];
// Set highlight
[ubOne setBackgroundImage:uimg2 forState:UIControlStateHighlighted];
// Set the default text yanse
[ubOne setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[ubOne setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];
// Set button frame To display
ubOne.frame = CGRectMake(50, 100, 100, 100);
// Set click event
[ubOne addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
// Add dynamically created buttons to
[self.view addSubview:ubOne];
}
-(void) buttonClick {
NSLog(@" Click. , Click events ");
}
@end
边栏推荐
- MySQL comparison
- CISP-PTE XSS基础
- UGUI
- What is digital twin? A real-time and virtual representation
- [high concurrency] the interviewer of ant financial asked me about thread pool!!
- puppeteer入门之 BrowserFetcher 类
- Cisp-pte XSS Foundation
- What are the differences between Parker pilot solenoid valve and direct acting solenoid valve?
- Dotween usage
- After four years of outsourcing, it was abandoned
猜你喜欢
随机推荐
启动jar
吴恩达机器学习课程-第七周
ZigBee模块通信协议的树形拓扑组网结构
Jmeter的使用(模拟高并发)
Using exec in PHP to display errors
宜居行星
Differences between beanfactorypostprocessor and beanpostprocessor
What are the functions and functions of the EMG actuator
转载:LinearLayout+Fragment实现下导航栏效果
puppeteer入门之 Puppeteer 类
With determination to forge ahead, JASMINER continues to deepen its brand strength
Mysql--索引
MD5学习
【bert】:在训练bert 语义相似的任务时,last ave state 的计算
Picture rule page turning
puppeteer入门之 Browser 类
Function and function of wandfluh proportional valve
EMG执行器的作用和功能有哪些
[high concurrency] the interviewer of ant financial asked me about thread pool!!
数据一致的问题









