iphone - Add fixed UILabel in UIPickerView -
i saw this question , answer , tried few options non worked.
i create uipickerview 1 below, (fixed labels inches , feet) wouldn't appear:
create uiimagepicker this:
- (void)viewdidload { _picker = [[uipickerview alloc] init]; cgrect pickerframe = cgrectmake(0, 0, 200, 216); pickerview.frame = pickerframe; pickerview.userinteractionenabled = yes; pickerview.datasource = self; pickerview.hidden = yes; pickerview.delegate = self; pickerview.showsselectionindicator = yes; [self.view addsubview:pickerview]; [textfield setinputview:pickerview]; textfield.delegate = self; [pickerview removefromsuperview]; _picker.hidden = yes; } - (bool) textfieldshouldbeginediting:(uitextview *)textview { if (textview.tag==1){ //field uipickerview _picker.hidden = no; [self addpickerlabel:@"feet" rightx:114 top:342 height:21]; [self addpickerlabel:@"inches" rightx:241 top:342 height:21]; } return yes; } - (void)addpickerlabel:(nsstring *)labelstring rightx:(cgfloat)rightx top:(cgfloat)top height:(cgfloat)height { #define picker_label_font_size 18 #define picker_label_alpha 0.7 uifont *font = [uifont boldsystemfontofsize:picker_label_font_size]; cgfloat x = rightx - [labelstring sizewithfont:font].width; // white label 1 pixel below, simulate embossing. uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(x, top + 1, rightx, height)]; label.text = labelstring; label.font = font; label.textcolor = [uicolor whitecolor]; label.backgroundcolor = [uicolor clearcolor]; label.opaque = no; label.alpha = picker_label_alpha; [_picker addsubview:label]; // actual label. label = [[uilabel alloc] initwithframe:cgrectmake(x, top, rightx, height)]; label.text = labelstring; label.font = font; label.textcolor = [uicolor blackcolor]; label.backgroundcolor = [uicolor clearcolor]; label.opaque = no; label.alpha = picker_label_alpha; [_picker addsubview:label]; }
the picker appears, without fixed labels of inches , feet.
what wrong?
move lines
viewdidload
, try it.labels need added once.not when textfield did begin editing[self addpickerlabel:@"feet" rightx:114 top:342 height:21]; [self addpickerlabel:@"inches" rightx:241 top:342 height:21];
log frame of both label , set correct if appears wrong
nslog(@"%@",nsstringfromcgrect(label.frame));
Comments
Post a Comment