IOS UI 第二篇:基本UI
1.UI书写:
{
UIControl *control;
UILabel *label;
}
control = [[UIControl alloc] initWithFrame:CGRectMake(10, 50, 300, 50)];
label.backgroundColor = [UIColor clearColor];
label.text = @"按我呀、好爽!";
label.textColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont boldSystemFontOfSize:30];
control.backgroundColor = [UIColor redColor];
[control addTarget:self action:@selector(onTouchDown:) forControlEvents:UIControlEventTouchDown];
[control addTarget:self action:@selector(onTouchup:) forControlEvents:UIControlEventTouchUpInside];
/*
三个参数
1、id调用哪个对象的方法
2、sel调用上面对象里的这个方法
3、controlevent 发生什么事件才调用上面传入的方法
*/
[self.window addSubview:control];
[self.window addSubview:label];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)onTouchDown:(id)sender{
NSLog(@"onTouchDown");
control.backgroundColor = [UIColor greenColor];
label.textColor = [UIColor blackColor];
}
-(void)onTouchup:(id)sender{
NSLog(@"onTouchUp");
control.backgroundColor = [UIColor redColor];
label.textColor = [UIColor whiteColor];
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoDark];
button.frame = CGRectMake(10, 50, 300, 50);
[button addTarget:self action:@selector(onButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor greenColor];
[self.window addSubview:button];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)onButtonClicked:(id)sender{
NSLog(@"按键被点击");
}
@interface Xib ()
@property (weak, nonatomic) IBOutlet UILabel *egg;
@property (weak, nonatomic) IBOutlet UILabel *bing;
@property (weak, nonatomic) IBOutlet UILabel *total;
@property (assign, nonatomic) int eggnumber;
@property (assign, nonatomic) int bingnumber;
@property (assign, nonatomic) CGFloat eggvalue;
@property (assign, nonatomic) CGFloat bingvalue;
@property (assign, nonatomic) CGFloat totalvalue;
@end
@implementation Xib
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_totalvalue = 1.2;
_eggvalue = 0;
_bingvalue = 0;
_eggnumber = 0;
_bingnumber = 0;
}
return self;
}
- (IBAction)Addegg:(id)sender {
++_eggnumber;
_eggvalue = 1*_eggnumber;
[_egg setText:[NSString stringWithFormat:@"%d鸡蛋--%.2lf元", _eggnumber, _eggvalue]];
_totalvalue+=1;
[_total setText:[NSString stringWithFormat:@"%.2lf元", _totalvalue]];
}
- (IBAction)Addbing:(id)sender {
++_bingnumber;
_bingvalue = 1.5*_bingnumber;
[_bing setText:[NSString stringWithFormat:@"%d煎饼--%.2lf元", _bingnumber, _bingvalue]];
_totalvalue+=1.5;
[_total setText:[NSString stringWithFormat:@"%.2lf元", _totalvalue]];
}
- (IBAction)Allupdate:(id)sender {
_totalvalue = 1.2;
_totalvalue = 1.2;
_eggvalue = 0;
_bingvalue = 0;
_eggnumber = 0;
_bingnumber = 0;
[_egg setText:[NSString stringWithFormat:@"%d鸡蛋--%.2lf元", _eggnumber, _eggvalue]];
[_bing setText:[NSString stringWithFormat:@"%d煎饼--%.2lf元", _bingnumber, _bingvalue]];
[_total setText:[NSString stringWithFormat:@"%.2lf元", _totalvalue]];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[_total setText:[NSString stringWithFormat:@"%.2lf元", _totalvalue]];
[_egg setText:[NSString stringWithFormat:@"%d鸡蛋--%.2lf元", _eggnumber, _eggvalue]];
[_bing setText:[NSString stringWithFormat:@"%d煎饼--%.2lf元", _bingnumber, _bingvalue]];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@interface Xib ()
@property (weak, nonatomic) IBOutlet UIButton *button1;
@property (weak, nonatomic) IBOutlet UIButton *button2;
@property (weak, nonatomic) IBOutlet UIButton *button3;
@property (weak, nonatomic) IBOutlet UIButton *button4;
@end
@implementation Xib
- (IBAction)selected_one:(id)sender {
_button1.selected = NO;
_button2.selected = NO;
_button3.selected = NO;
_button4.selected = NO;
UIButton *btn = sender;
btn.selected = YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@interface Xib ()
@property (weak, nonatomic) IBOutlet UILabel *pic;
@property (weak, nonatomic) IBOutlet UILabel *label_1;
@property (weak, nonatomic) IBOutlet UILabel *label_2;
@property (weak, nonatomic) IBOutlet UIButton *button;
@end
@implementation Xib
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[_pic setHidden:YES];
}
return self;
}
- (IBAction)Recoder:(id)sender {
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self begin];
// Do any additional setup after loading the view from its nib.
}
-(void)begin{
[_pic setHidden:YES];
[_label_1 setHidden:YES];
[_label_2 setHidden:YES];
[_button addTarget:self action:@selector(onButtonClicked:) forControlEvents:UIControlEventTouchDown];
[_button addTarget:self action:@selector(onButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[_button addTarget:self action:@selector(onButtonClickup:) forControlEvents:UIControlEventTouchDragOutside];
[_button addTarget:self action:@selector(onButtonClickupa:) forControlEvents:UIControlEventTouchUpOutside];
[_button addTarget:self action:@selector(onButtonClickupb:) forControlEvents:UIControlEventTouchDragInside];
}
-(void)onButtonClicked:(id)sender{
[_pic setHidden:NO];
[_label_1 setHidden:NO];
[_label_2 setHidden:NO];
_label_2.text = @"上滑取消发送";
[_button setTitle:@"松手取消" forState:UIControlStateHighlighted];
}
-(void)onButtonClick:(id)sender{
[_pic setHidden:NO];
[_label_1 setHidden:YES];
[_label_2 setHidden:NO];
_label_2.text = @"发送成功";
[_button setTitle:@"点击录音" forState:UIControlStateHighlighted];
}
-(void)onButtonClickup:(id)sender{
[_pic setHidden:NO];
[_label_1 setHidden:YES];
[_label_2 setHidden:NO];
_label_2.text = @"松手取消";
[_button setTitle:@"松手发送" forState:UIControlStateHighlighted];
}
-(void)onButtonClickupa:(id)sender{
[_pic setHidden:NO];
[_label_1 setHidden:YES];
[_label_2 setHidden:NO];
_label_2.text = @"取消成功";
[_button setTitle:@"松手取消" forState:UIControlStateHighlighted];
}
-(void)onButtonClickupb:(id)sender{
[_pic setHidden:NO];
[_label_1 setHidden:YES];
[_label_2 setHidden:NO];
_label_2.text = @"松手发送";
[_button setTitle:@"松手发送" forState:UIControlStateHighlighted];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
[self begin];
}
@end
@implementation AppDelegate
{
UIButton *customButton;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoDark];
button.frame = CGRectMake(10, 50, 300, 50);
[button addTarget:self action:@selector(onButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(onButtondown:) forControlEvents:UIControlEventTouchDown];
button.backgroundColor = [UIColor greenColor];
customButton = [UIButton buttonWithType:UIButtonTypeCustom];
customButton.frame = CGRectMake(10, 100, 300, 50);
//customButton.backgroundColor = [UIColor blueColor];
//customButton.titleLabel.text = @"xxx";
//customButton.titleLabel.textColor = [UIColor blackColor];
[customButton setTitle:@"nonal" forState:UIControlStateNormal];
[customButton setTitle:@"HIGHnonal" forState:UIControlStateHighlighted];
[customButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[customButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
UIImage *imageNor = [UIImage imageNamed:@"pic1.png"];
UIImage *imagePre = [UIImage imageNamed:@"pic2.png"];
[customButton setBackgroundImage:imageNor forState:UIControlStateNormal];
[customButton setBackgroundImage:imagePre forState:UIControlStateHighlighted];
// [customButton addTarget:self action:@selector(onButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:customButton];
[self.window addSubview:button];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)onButtonClicked:(id)sender{
NSLog(@"按键被点击");
customButton.highlighted = NO;
[customButton setTitle:@"nonal" forState:UIControlStateNormal];
}
-(void)onButtondown:(id)sender{
customButton.highlighted = YES;
}
IOS UI 第二篇:基本UI的更多相关文章
- IOS设计模式第二篇之单例设计模式
现在我们的组件已经有组织了.你需要从其他的地方得到数据,你也可以创建一个API类管理数据这个下个设计模式单例里面介绍. 这个单例设计模式确保这个类仅仅拥有一个实例,并且为这个实例提供一个全局的访问点. ...
- Jerry的WebClient UI 42篇原创文章合集
我要感谢CRM On Premise, 因为在这个产品上做开发让我得以使用WebClient UI框架.有些朋友觉得这个SAP自己发明的基于HTML+ABAP的MVC框架,和现在流行的三驾马车(Ang ...
- iOS编程实战 — 新的UI范式
iOS 7给苹果设备带来了全新的用户界面(UI).iOS 7在UI上的变化是自其诞生以来最大的.iOS 7专注于三个重要的特点:清晰.依从和层次.理解这三个特点很重要,因为这有助于设计跟原生的系统内置 ...
- WPF 精修篇 非UI进程后台更新UI进程
原文:WPF 精修篇 非UI进程后台更新UI进程 <Grid> <Grid.RowDefinitions> <RowDefinition Height="11* ...
- iOS开发——高级技术精选&底层开发之越狱开发第二篇
底层开发之越狱开发第二篇 今天项目中要用到检查iPhone是否越狱的方法. Umeng统计的Mobclick.h里面已经包含了越狱检测的代码,可以直接使用 /*方法名: * isJailbroken ...
- iOS系列 基础篇 03 探究应用生命周期
iOS系列 基础篇 03 探究应用生命周期 目录: 1. 非运行状态 - 应用启动场景 2. 点击Home键 - 应用退出场景 3. 挂起重新运行场景 4. 内存清除 - 应用终止场景 5. 结尾 本 ...
- [转]Android开源项目第二篇——工具库篇
本文为那些不错的Android开源项目第二篇--开发工具库篇,主要介绍常用的开发库,包括依赖注入框架.图片缓存.网络相关.数据库ORM建模.Android公共库.Android 高版本向低版本兼容.多 ...
- iOS开发多线程篇—NSOperation基本操作
iOS开发多线程篇—NSOperation基本操作 一.并发数 (1)并发数:同时执⾏行的任务数.比如,同时开3个线程执行3个任务,并发数就是3 (2)最大并发数:同一时间最多只能执行的任务的个数. ...
- Android开源项目第二篇——工具库篇
本文为那些不错的Android开源项目第二篇——开发工具库篇,**主要介绍常用的开发库,包括依赖注入框架.图片缓存.网络相关.数据库ORM建模.Android公共库.Android 高版本向低版本兼容 ...
随机推荐
- react.js 从零开始(二)组件的生命周期
什么是生命周期? 组件本质上是一个状态机,输入确定,输出一定确定. 当状态改变的时候 会触发不同的钩子函数,可以让开发者做出响应.. 一个组件的生命周期可以概括为 初始化:状态下 可以自定义的函数 g ...
- 使用pfile 启动oracle 实例时,启动失败---db_recovery_file_dest參数值在os上不存在。
[oracle@vm22 ~]$ export ORACLE_SID=orcl [oracle@vm22 ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2. ...
- IC设计前端到后端的流程和eda工具。
IC前端设计(逻辑设计)和后端设计(物理设计)的区分:以设计是否与工艺有关来区分二者:从设计程度上来讲,前端设计的结果就是得到了芯片的门级网表电路. 前端设计的流程及使用的EDA工具例如以下: 1.架 ...
- MyEclipse2014 设备 checkstyle、PMD、findbugs 最简单的方法 详细说明
最近的实验需要的代码审查和应用程序性能优化.在需求MyEclipse安装某些插件,由于如今的MyEclipse版本号和大多数教程的不一样了,一些安装选项也已经改变,所以安装起来非常费事,通过不断的尝试 ...
- uva10827-Maximum sum on a torus(矩阵最大和的变形)
题目;uva10827-Maximum sum on a torus(矩阵最大和的变形) 题目大意:就是uva108的变形,矩阵能够连通,就是能够从后面连到前面.这里把矩阵复制三遍,然后又一次生成一个 ...
- C++调用一个成员函数的需求this指针的情况
1.虚成员函数,因为需要this展望虚表指针的指针 2.在数据成员的操作部件的功能 #include "stdafx.h" #include <iostream> #i ...
- eclipse打不开data目录解决的方法
1.首先手机必须详细root权限.没有的话,先去root. 2.root过后若还是不能打开,下载一个R.E管理器,然后将须要打开的目录设置为可读.可写.可运行. 附图:
- 【Unity 3D】学习笔记三十八:角色控制器
角色控制器 在unity中,已经帮我们实现的上下左右跳等动作,并将他们封装成了角色控制器.角色控制器保存在unity标准资源包中,能够说是很的强大.能够模拟第一或者第三人称视角.不受刚体的限制,很适用 ...
- Codeforces 437D The Child and Zoo(贪心+并查集)
题目链接:Codeforces 437D The Child and Zoo 题目大意:小孩子去參观动物园,动物园分非常多个区,每一个区有若干种动物,拥有的动物种数作为该区的权值.然后有m条路,每条路 ...
- Hibeernate中的两种分页方式
1. return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(S ...