1.预置按钮类型

  sdk提供了5个预置按钮类型:Detail Disclosure,Info Light,Info Dark,Contact Add,Rounded Rectangle。它们添加到sdk中首先是为了方便苹果公司自己。

  构造方式:[UIButton buttonWithType:UIButtonTypeContactAdd];

 

2.显示系统私有UIButton风格

     指定 值为100 以上的UIButton的buttonWithType可以得到非公开的按钮风格,像红色按钮,黑色按钮,箭头返回按钮等。

     对于某种风格,可以用[button setTintColor:[UIColor blueColor]];来改变按钮颜色。

     参考 

     http://zhaohaiyang.blog.51cto.com/2056753/756082

 

3.图片和文字环绕

   UIButtonTypeCustom按钮可以设置title。

   若置title于图像上面时,可使用setBackgroundImage;

   若置title于图像右边时,可使用setImage,且要设置frame宽度大于图像,以能显示出title文字。

   设置titleEdgeInsets可实现文字到图片下方,不过要经过一翻计算。

   setImage的图的Z坐标是最高的。

 

4.光晕效果

   button.showsTouchWhenHighlighted=YES;点击时的闪光效果会被前景图片遮住中间部分;

   Shows Touch On Highlight (高亮)光晕的大小是55x55像素,大于40x40像素的按钮不能使用该视觉效果。

 

5.指定目标函数传递的参数问题

  例如 

   [button addTarget:self action:@selector(tableView:accessoryButtonTappedForRowWithIndexPath:)  forControlEvents:UIControlEventTouchUpInside];,

  在执行时,传递给tableView函数的参数类型分别是UIButton类型和UITouchesEvent类型。即不论函数原型是什么,button实际传递的参数类型是固定的。

 

6.点击测试UIButton响应UIControlEventTouchUpInside事件时,响应点超出了它button的范围。

 

7.在UIButton中addSubview的问题

   UIView的userInteractionEnabled值默认为YES,必须设置UIButton所有的subview的userInteractionEnabled为NO,才能让UIButton正常响应点击。

   但是如果设置了UIView的setUserInteractionEnabled为NO,其子view都将得不到响应。

 

8.处理双击问题

   [button addTarget:self action:@selector(onTouchUpInside:withEvent:) forControlEvents:UIControlEventTouchUpInside];

   -(void)onTouchUpInside:(id)sender withEvent:(UIEvent*)event 
{
    UITouch* touch = [[event allTouches] anyObject];
    NSLog(@"onTouchUpInside tagCount:%d",touch.tapCount);

    //判断点击次数
    if (touch.tapCount == 1) 
    {

       //todo
    }
}

posted on 2013-02-27 11:20  111111***  阅读(2942)  评论(0编辑  收藏  举报