zoukankan      html  css  js  c++  java
  • iPhone控件之UIButton

    #import "UITestViewController.h"

    @implementation UITestViewController

    -(void)buttonDown:(id)sender
    {
    NSLog(@"Button pushed down");
    }

    -(void)buttonRelease:(id)sender
    {
    NSLog(@"Button released");
    }

    -(void)checkboxClick:(UIButton *)btn
    {
    btn.selected = !btn.selected;
    }

    - (void)viewDidLoad {

    [super viewDidLoad];

    //rounded-rect button
    UIButton *roundedRectButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    CGRect buttonRect = CGRectMake(100,50,100,35);
    [roundedRectButton setFrame:buttonRect];

    [roundedRectButton setTitle:@"Normal" forState:UIControlStateNormal];
    [roundedRectButton setTitle:@"Highlighted" forState:UIControlStateHighlighted];
    roundedRectButton.showsTouchWhenHighlighted = YES;

    [roundedRectButton addTarget:self action:@selector(buttonDown:) forControlEvents:UIControlEventTouchDown];
    [roundedRectButton addTarget:self action:@selector(buttonRelease:) forControlEvents:UIControlEventTouchUpInside];

    //checkbox control
    UIButton *checkbox = [UIButton buttonWithType:UIButtonTypeCustom];

    CGRect checkboxRect = CGRectMake(135,150,36,36);
    [checkbox setFrame:checkboxRect];

    [checkbox setImage:[UIImage imageNamed:@"checkbox_off.png"] forState:UIControlStateNormal];
    [checkbox setImage:[UIImage imageNamed:@"checkbox_on.png"] forState:UIControlStateSelected];

    [checkbox addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];

    //custom circular button
    UIButton *circularButton = [UIButton buttonWithType:UIButtonTypeCustom];

    CGRect circularRect = CGRectMake(80,220,165,164);
    [circularButton setFrame:circularRect];

    UIImage *buttonImage = [UIImage imageNamed:@"circular_button.png"];
    [circularButton setImage:buttonImage forState:UIControlStateNormal];

    [circularButton addTarget:self action:@selector(buttonDown:) forControlEvents:UIControlEventTouchUpInside];

    //add all the buttons to the main view
    [self.view addSubview:roundedRectButton];
    [self.view addSubview:checkbox];
    [self.view addSubview:circularButton];
    }
  • 相关阅读:
    Atitit 数据库view视图使用推荐规范与最佳实践与方法
    Atitit mybatis快速开发 的sql api接口
    一个数据包经过路由器和交换机各会发生什么变化
    c preprocessor
    A database of opensource HTTP proxies written in python.
    google chrome os下载
    一道笔试题多字串查找
    一个老题:将正整数n分为若干num个不同的正整数之和
    web dev framework
    memory leakage
  • 原文地址:https://www.cnblogs.com/foxmin/p/2393609.html
Copyright © 2011-2022 走看看