I have a problem regarding to set UIButton frame.
NSSt开发者_运维技巧ring *sample = @"Demo to set display view on label in iPhone";
CGSize maximumLabelSize = CGSizeMake(55,9999);
expectedLabelSize = [sample sizeWithFont:[UIFont systemFontOfSize:20]
constrainedToSize:maximumLabelSize
lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"%f",expectedLabelSize.height);
self.label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, expectedLabelSize.width, expectedLabelSize.height)];
self.label.backgroundColor = [UIColor clearColor];
self.label.numberOfLines = 0;
self.label.text = sample;
[self.label sizeToFit];
So in below uibutton code how to set frame position of text so that only "iPhone" word is clickable?
self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.button.frame = CGRectMake(self.label.frame.origin.x,
self.label.frame.origin.y+50,
expectedLabelSize.width,
expectedLabelSize.height);
To make just one word of a UILabel clickable as a hyperlink you would need to know exactly where the UILabel puts that word. That is difficult (not impossible) especially with a multiple line label and especially if you allow resizing of the font to make the text fit.
Why not use a UIWebView and make it a hyperlink instead? Or separate the text that is clickable and put that text into the UIButton by itself, like:
label.text = @"Demo to set display view on label in ";
button.titleLabel.text = @"iPhone";
Note: you should not checkmark this answer if your problem is not solved.
精彩评论