<h2>OBShapedButton的使用</h2>
OBShapedButton是一个开源的第三方库,主要用于处理不规则button的显示,这个库是继承子UIButton的子类。
OBShapedButton 使用也比较简单,直接自定义一个继承OBShapedButton的子类button就可以了,它可以根据透明像素点来判断点击时,那个button是可以响应事件,从而实现不规则button的布局。
使用很简单直接创建代码就行了:
NSArray* array=[NSArray arrayWithObjects:@"A004.png",@"A003.png",@"A002.png",@"A001.png",@"A007.png",@"A006.png",@"A005.png",@"C001.png", nil];
NSArray* selectarray=[NSArray arrayWithObjects:@"main_car_position",@"main_car_light_close",@"main_car_whistle_close",@"main_car_door_lock",@"main_car_door_unlock",@"main_car_whistle_open",@"main_car_light_open",@"main_quit", nil];
for (int i = 0; i<array.count; i++) {
OBShapedButton* button=[[OBShapedButton alloc] init];
button.tag=i+100;
//防止多点触摸
[button setExclusiveTouch:YES];
button.bounds=CGRectMake(0, 0, 300, 300);
button.center = self.view.center;
[button setBackgroundImage:[UIImage imageNamed:selectarray[i]] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:array[i]] forState:UIControlStateSelected];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}