ui-label button

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate{
    //全局变量
    UILabel*lablel;
}
-(void)dealloc{
    self.window=nil;
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];

    //创建lablel
    lablel=[[UILabel alloc]initWithFrame:CGRectMake(20, 100, 280, 30)];
    lablel.backgroundColor = [UIColor brownColor];

    //设置文本
    lablel.text = @"你好,helle world 你好,helle world 你好,helle world";
    //设置文本颜色
    lablel.textColor = [UIColor whiteColor];
    //设置文本行数
    lablel.numberOfLines = 0;
    //文本对齐方式
    //lablel.textAlignment = NSTextAlignmentLeft;
    //lablel.textAlignment = NSTextAlignmentRight;
    lablel.textAlignment = NSTextAlignmentCenter;

    //获取系统的字体
    NSLog(@"%@",[UIFont familyNames]);
    //设置字体和字号
    lablel.font = [UIFont fontWithName:@"Tamil Sangam MN" size:15];
    //加粗
    lablel.font = [UIFont boldSystemFontOfSize:20];
    //斜体
    //lablel.font = [UIFont italicSystemFontOfSize:20];

    //阴影颜色
    //lablel.shadowColor = [UIColor redColor];
    //阴影偏移
    //lablel.shadowOffset  = CGSizeMake(0, -10);

    //省略........
    //lablel.lineBreakMode =NSLineBreakByTruncatingHead;//首部省略
    //lablel.lineBreakMode =NSLineBreakByTruncatingMiddle;//中间省略
    //lablel.lineBreakMode =NSLineBreakByTruncatingTail;//尾部省略

    //高亮状态
    lablel.highlighted = YES;
    //高亮字体颜色
    lablel.highlightedTextColor = [UIColor greenColor];

    //lablel自适应
    //自动获取文本内容承载范围
    //[lablel sizeToFit];
    [self.window addSubview:lablel];
    [lablel release];

    //创建方式为类方法
    //主要响应事件
    //自定义UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    btn.backgroundColor = [UIColor brownColor];
    btn.frame = CGRectMake(20, 300, 200, 200);
    //按钮状态-设置文字与颜色
    //普通状态
    [btn setTitle:@"点我呀" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //高亮状态
    [btn setTitle:@"别点我" forState:UIControlStateHighlighted];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    //禁用
    //[btn setTitle:@"禁用" forState:UIControlStateDisabled];
    //btn.enabled = YES;

    //设置按钮阴影颜色与偏移
    //[btn setTitleShadowColor:[UIColor greenColor] forState:UIControlStateNormal];
    //btn.titleShadowOffset = CGSizeMake(5, 5);

    //这样插入不推荐
    //[btn setImage:[UIImage imageNamed:@"Button_foot1"] forState:UIControlStateNormal];

    //把图片拉升至btn的size大小
    [btn setBackgroundImage:[UIImage imageNamed:@"Button_foot1"] forState:UIControlStateNormal];

    //创建uiimage对象
    UIImage*image = [UIImage imageNamed:@"checked"];

    //选中状态
    [btn setBackgroundImage:image forState:UIControlStateSelected];
    btn.selected = NO;
    btn.showsTouchWhenHighlighted = YES;
    //    btn.imageView
    //    btn.titleLabel

    lablel.text = @"0";
    //添加事件
    [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside ];
//    [btn addTarget:self action:@selector(onClick:
//) forControlEvents:UIControlEventTouchDown ];
    [self.window addSubview:btn];

    return YES;
}

-(void)onClick:(UIButton*)sender{
    NSInteger n =[lablel.text intValue]+1;
    lablel.text = [NSString stringWithFormat:@"%d",n];
    NSLog(@"%@",lablel.text);
    //    if (sender.selected == NO) {
    //         sender.selected = YES;
    //    }
    //    else
    //    {
    //        sender.selected = NO;
    //    }
    //    sender.enabled = NO;
    //可切换点击图标
    sender.selected = ! sender.selected;

}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
时间: 2024-08-26 14:03:47

ui-label button的相关文章

iOS开发UI篇—Button基础

iOS开发UI篇—Button基础 一.简单说明 一般情况下,点击某个控件后,会做出相应反应的都是按钮 按钮的功能比较多,既能显示文字,又能显示图片,还能随时调整内部图片和文字的位置 二.按钮的三种状态 normal(普通状态) 默认情况(Default) 对应的枚举常量:UIControlStateNormal highlighted(高亮状态) 按钮被按下去的时候(手指还未松开) 对应的枚举常量:UIControlStateHighlighted disabled(失效状态,不可用状态) 如

iOS系列 基础篇 06 标签和按钮 (Label & Button)

iOS系列 基础篇 06 标签和按钮 (Label & Button) 目录: 标签控件 按钮控件 小结 标签和按钮是两个常用的控件,下面咱们逐一学习. 1. 标签控件 使用Single View Application模板创建一个名为“LabelAndButtonSimple”的工程 (PS:具体创建过程和各设置项介绍等可参见前面的文章,这里就截图简单带过了:) (1) 打开Xcode,选择Create a new Xcode Project: (2) 选择Single View Applic

UI——label--button

-----------  了解iphone-------- iphone 4/4s 尺寸:3.5英寸 分辨率:640*960 实际的点(大小):320*480 iphone 5/5s 尺寸:4.0英寸 分辨率:640*1136 实际的点:320*568 iphone6 尺寸:4.7 分辨率:750*1334 实际屏幕的点:(375*667) iphone Plus 尺寸:5.5 分辨率:1080*1920 实际:(540*960): 怎么设置标签的位置 (需要设置的标签左上角的坐标以及大小(长,

Unity学习笔记 之 触发Unity UI 的 Button 事件 的代码记录

首先奉献上 Button 所触发的事件 的脚本代码. 文件名为testButtonEvent using UnityEngine; using System.Collections; //1.引入 UI . using UnityEngine.UI; public class testButtonEvent : MonoBehaviour { //2.定义一个目标对象. public Text targetTextObject; // Use this for initialization vo

Android常用UI组件 - Button

按钮(Button)是Android当中一个常用的UI组件,很小但是在开发中最常用到.一般通过与监听器结合使用,从而触发一些特定事件. Button继承了TextView.它的功能就是提供一个按钮,这个按钮可以供用户点击,当用户对按钮进行操作的时候,触发相应事件,如点击,触摸.一 般对于一个按钮而言,用的最多的就是点击事件,Button间接继承自View,而Android UI中的所有事件,都是定义在View中的. 实例:ButtonDemo 运行效果: 代码清单: 布局文件:main.xml

jQuery Easy UI LinkButton(button)包

LinkButton(button)包,easyui其中一个基本组成部分 演示样例: <!DOCTYPE html> <html> <head> <title>jQuery Easy UI</title> <meta charset="UTF-8" /> <script type="text/javascript" src="easyui/jquery.min.js"&

Android经常使用UI组件 - Button

button(Button)是Android其中一个经常使用的UI组件.非常小可是在开发中最经常使用到.一般通过与监听器结合使用.从而触发一些特定事件. Button继承了TextView.它的功能就是提供一个button,这个button能够供用户点击.当用户对button进行操作的时候,触发对应事件,如点击.触摸.一般对于一个button而言,用的最多的就是点击事件,Button间接继承自View.而Android UI中的全部事件.都是定义在View中的. 实例:ButtonDemo 执行

tkinter之 Label &amp; Button 标签和按钮

''' # ------------------------------------------------------------ # # 1. 使用tkinter设置一个标签 # # # 设计tkinter内容: title:geometry:Label:mainloop # ------------------------------------------------------------ '''   代码如下: import tkinter as tk window = tk.Tk(

iOS开发UI篇——Button基础

一.简单说明 一般情况下,点击某个控件后,会做出相应反应的都是按钮 按钮的功能比较多,既能显示文字,又能显示图片,还能随时调整内部图片和文字的位置 二.按钮的三种状态 1. normal(普通状态) 默认情况(Default) 对应的枚举常量:UIControlStateNormal 2. highlighted(高亮状态) 按钮被按下去的时候(手指还未松开) 对应的枚举常量:UIControlStateHighlighted 3. disabled(失效状态,不可用状态) 如果enabled属

OS开发UI篇—Button基础

1.1.简单说明 一般情况下,点击某个控件后,会做出相应反应的都是按钮 按钮的功能比较多,既能显示文字,又能显示图片,还能随时调整内部图片和文字的位置 1.2.按钮的三种状态 normal(普通状态) 默认情况(Default) 对应的枚举常量:UIControlStateNormal highlighted(高亮状态) 按钮被按下去的时候(手指还未松开) 对应的枚举常量:UIControlStateHighlighted disabled(失效状态,不可用状态) 如果enabled属性为NO,