<h2>OBShapedButton的使用</h2>
OBShapedButton是一個開源的第三方庫棍鳖,主要用于處理不規(guī)則button的顯示,這個庫是繼承子UIButton的子類术辐。
OBShapedButton 使用也比較簡單,直接自定義一個繼承OBShapedButton的子類button就可以了施无,它可以根據(jù)透明像素點來判斷點擊時辉词,那個button是可以響應(yīng)事件,從而實現(xiàn)不規(guī)則button的布局猾骡。
使用很簡單直接創(chuàng)建代碼就行了:
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];
}
屏幕快照 2017-05-13 下午10.19.24.png