开发者

Image with Title at bottom

Is there any special control available in UIKit to display a screen like iPhone's app listing screen开发者_StackOverflow中文版, i.e. Image with title at bottom


I am not aware of any controls available in the base libraries to do what you mention. However it would not be very difficult to simply subclass a UIImageView so that it includes a UILabel located just below the image. This can be done in many ways and is not very hard.

A basic idea would be something like:

Header:

@interface ImageTextView : UIImageView  {
    UILabel *title; 
}

-(id) initWithFrame:(CGRect)_frame;
-(void) setTitle:(NSString *)_title; 

@end

Implementation:

@implementation ImageTextView

-(id) initWithFrame:(CGRect)_frame{
    if (self = [super initWithFrame:_frame]){
        self.layer.masksToBounds = NO; 
        title = [[UILabel alloc] initWithFrame:(CGRect){0,_frame.size.height,_frame.size.width,50}];
        title.backgroundColor = [UIColor clearColor];
        title.textColor = [UIColor whiteColor]; 
        title.textAlignment = UITextAlignmentCenter;
        [self addSubview:title]; 
    }

    return self; 
}

-(void) setTitle:(NSString *)_title{
    title.text = _title; 
}

-(void) dealloc{
    [title release]; 
    [super dealloc];
}

@end

And then to use it you would use code like:

ImageTextView *test = [[ImageTextView alloc] initWithFrame:(CGRect){0,0,100,100}];
test.image = [UIImage imageNamed:@"example.png"];
[test setTitle:@"TEST"];
[mainView addSubview:test];

Hope this helps.

Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜