//author:smilelance
//from:
#import
@inte***ce pdesegmentcontrol : uiview
@property (readonly, nonatomic) nsinteger selectedsegmentindex;
- (id) initwithframe:(cgrect)frame items:(nsarray*)itemarray;
-(void)setsegmentindex:(nsinteger)index;
//segment control
// nsarray * segmentitems = [nsarray arraywithobjects: @"未審批", @"已審批", nil];
// uisegmentedcontrol *segmentedcontrol = [[uisegmentedcontrol alloc] initwithitems: segmentitems];
// segmentedcontrol.frame = cgrectmake(310, 295, 160, 36);
// [segmentedcontrol addtarget:self action:@selector(segmentaction:) forcontrolevents:uicontroleventvaluechanged];
// segmentedcontrol.segmentedcontrolstyle = uisegmentedcontrolstylebordered;
// segmentedcontrol.selectedsegmentindex = 0;
// myborrowrequesttype = segmentedcontrol.selectedsegmentindex;
// [self.view addsubview:segmentedcontrol];
@end
#import "pdesegmentcontrol.h"
#define segment_unselected 0
#define segment_selected 1
@implementation pdesegmentcontrol
- (id)initwithframe:(cgrect)frame
returnself; }
- (id) initwithframe:(cgrect)frame items:(nsarray*)itemarray
else
if(i==segmentcount-1)else
button.tag = i;
[button addtarget:
self
action:
@selector
(segmentaction:) forcontrolevents:uicontroleventtouchupinside];
[button settitle:[itemarray objectatindex:i] forstate:uicontrolstatenormal];
[segmentbuttons
addobject:button];
[self
addsubview:button];}[
self
setsegmentindex:0];
}returnself; }
-(void)setsegmentindex:(nsinteger)index
-(void)segmentaction:(id)sender
uibutton *segbutton = [segmentbuttons
objectatindex:i];
[segbutton setbackgroundimage:[uiimage
imagenamed:[buttonimgnames
objectatindex:i*2+nameoffset]]
forstate:uicontrolstatenormal];}}
/*// only override drawrect: if you perform custom drawing.
// an empty implementation adversely affects performance during animation.
- (void)drawrect:(cgrect)rect
*/@end
iOS自定義的UISwitch按鈕
因為專案需要在uiswitch按鈕上寫文字,系統自帶的uiswitch是這樣的 既不能寫字,也不能改顏色,於是在網上找到了這麼乙個自定義的switch按鈕,具體出處找不見了。記錄一下,怕以後找不見了。先看下效果圖 按鈕的樣式很多,可以文字,可以寫多行,文字大小和顏色都可以設定。看下它的原始碼 imp...
iOS 自定義textView鍵盤收回按鈕
diytextview.h textreturndemo created by 低調 愛 on 16 3 7.diytextview.h檔案 自定義.h檔案 define hotspot statusbar height 20 define sys statusbar height 20 獲取螢幕寬...
Android 自定義按鈕
將按鈕的背景顏色設定成drawable檔案即可。雖然這裡講的是button,但是textview及其子元件也可以如法炮製 主布局檔案如下 下面三個檔案都放在drawable hdpi資料夾下,第乙個是my button selector.xml,定義了按鈕的不同狀態 my button presse...