Question

This question is for the iOS development platform.

I am looking for something that will have some text on it and will recognize taps. Once tapped, it will do some stuff and change the text on itself. (It will be a part of a game like app).

At first I considered using a UIButton with a custom image. But on trying to change the text on it, I realized that it is read-only.

Then I considered using a UILabel, but it didn't suit my use as, at a later stage, I would like to make the View have a custom shape with an outline.

Right now, I am considering adding a generic UIView and add a Label as a subView to it. (Can I give the UIView a custom shape?)

Please can someone point out a better solution or if I am wrong above.

Was it helpful?

Solution 2

As Desdenova said, his solution worked for me.

UIButton's title isn't read only. You can use setTitle:forState: method.

OTHER TIPS

For creating custom shaped objects use UIbezierPath. Through UIbezierPath we can create custom shaped UIViews. Touch inside those views can handle adding gestures to that views.

Sample:-

UIBezierPath* path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(view.frame.size.width, 0)];
[path addLineToPoint:CGPointMake(view.frame.size.width, [self headerBackGroundView].frame.size.height)];
[path addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)];

[path setLineWidth:1.0];

[[UIColor lightGrayColor] setStroke];

[path stroke];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top