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 高版本向低版本兼容 ...
随机推荐
- HDU 2082-找单词(母函数)
找单词 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- 如何让格斗游戏的横版过关(2) Cocos2d-x 2.0.4
在第一章<如何使横版格戏>基础上.添加角色运动.碰撞.敌人.AI和音乐音效,原文<How To Make A Side-Scrolling Beat 'Em Up Game Like ...
- IOS ARC和非ARC文件混用
ARC在SDK4.0的时候增加的,因为要和曾经的项目融合,就会有arc和非arc文件的混合. 当然,也就这两种情况: 1.自己的旧项目没有使用ARC,可是引入的第三方库却是使用了ARC的. 2.自己的 ...
- elasticsearch的rest搜索---mapping
目录: 一.针对这次装B 的解释 二.下载,安装插件elasticsearch-1.7.0 三.索引的mapping 四. 查询 五.对于相关度的大牛的文档 三.mapping 1. 索引的map ...
- Swift得知——使用和分类功能(四)
Swift得知--使用和分类功能(四) 总结Swift该功能使用的总可分为七类 1 ---- 没有返回值,没有參数的函数 2 ---- 有參数和返回值的函数 3 ---- 使用元祖来返回多个值 4 - ...
- iOS开发分析"秘密"App内容页面的效果(两)
@我前几天写的"秘密"的Cell制品的效果,想要的效果还是有差距,并且扩展性非常不好,于是重写封装,把总体视图都放到scrollView中,基本是和secret app 一模一样的 ...
- JQuery日记6.5 Javascript异步模式(一)
理解力JQuery前实现异步队列,有必要理解javascript异步模式. Javascript异步其实并不严重格异步感,js使某些片段异步方式在将来运行,流不必等待继续向下进行. 在多线程的语言中最 ...
- Delta3D 2.8版本号 预习
http://blog.csdn.net/zhuyingqingfen/article/details/38581453 看到官网今天的更新.发现即将公布的delta3d 2.8 版本号 做了非常大的 ...
- 互联网创业应该如何找到创意 - RethinkDB创始人Slava Akhmechet的几点建议
关于作者 我叫Slava Akhmechet,本人是 RethinkDB 的创始人之一,RethinkDB是一个设计来帮助开发者和运营团队来处理无结构数据的一个开源的分布式数据库,用户可以使用它来作为 ...
- iOS7 UIKit动力学-碰撞特性UICollisionBehavior 上
我们谈到了重力上述财产UIGravityBehavior这个类. 非常明确的看法,当我们添加的属性的严重性后,,苹果UIview像掉进无底洞,地下坠,不断的加速.而如今呢,我们要在这个手机屏幕上,加入 ...