How can one draw a progressbar inside a UITextField ? I have tested two ways so far.
1. Add a UIProgressView object as a subview of the UITextField object.
UIProgressView* progressView = [[UIProgressView alloc] init];
[aUITextField addSubview:progressView];
progressView.progress = 0.5;
[progressView release];
2. Subclass UITextfield and override drawRect:.
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
[self setBackgroundColor:[UIColor clearColor]];
}
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code
[[UIColor orangeColor] setFill];
[[UIBezierPath bezierPathWithOvalInRect:rect] fill];
}
Both approaches didn’t work. Do you see any problem with these approaches? And how can I make this work?
I am not sure adding the
UIProgressViewas a subview of aUITextFieldobject will be useful as you can’t change the frame of the progress view.Subclassing seems to be the right approach. Here is what I could come up with. Check if it is useful to you.
ProgressField.h
ProgressField.m
This doesn’t seem to work with
UITextFields withborderStyleset toUITextBorderStyleRoundedRect.