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];
    }
  • 相关阅读:
    bzoj 3779: 重组病毒【LCT+线段树维护dfs序】
    bzoj 4817: [Sdoi2017]树点涂色【树链剖分+LCT】
    bzoj 4818: [Sdoi2017]序列计数【容斥原理+dp+矩阵乘法】
    bzoj 1853: [Scoi2010]幸运数字&&2393: Cirno的完美算数教室【容斥原理】
    bzoj 3589: 动态树【树链剖分+容斥】
    bzoj 1042: [HAOI2008]硬币购物【容斥原理+dp】
    bzoj 4517: [Sdoi2016]排列计数【容斥原理+组合数学】
    好听的英文歌曲
    颜色色环
    颜色模式
  • 原文地址:https://www.cnblogs.com/foxmin/p/2393609.html
Copyright © 2011-2022 走看看