Objective C,iOS,有哪些选项可以在 UIImageView 中的图像顶部添加一些文本?
我需要以编程方式添加一些数字/文本,以便它显示在我为多个 UIImageView 指定的图像顶部。我的用户还可以在屏幕上拖动图像视图。我需要文字同时移动。要移动图像视图,我使用此代码。
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for (id football in multipleFootballs) {
UITouch *touch = [touches anyObject];
if ([touch view] == football) {
CGPoint pt = [[touches anyObject] locationInView:football];
CGRect frame = [football frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[football setFrame:frame];
}
}
}
I need to add some numbers / text, programmatically so it shows on top of an image I have specified for several UIImageViews. Also my users are able to drag the image view around the screen. I need the text to move at the same time. To move the image views I use this code..
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for (id football in multipleFootballs) {
UITouch *touch = [touches anyObject];
if ([touch view] == football) {
CGPoint pt = [[touches anyObject] locationInView:football];
CGRect frame = [football frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[football setFrame:frame];
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几乎任何
UIView
或UIView
后代都可以作为子视图添加到任何其他UIView
中。因此,您可以使用文本创建一个UILabel
,并将其作为子视图添加到您的UIImageViews
中,使用UILabel< 的适当的
CGRect
/code> 的框架将其放置在UIImageView
中您想要的位置。Just about any
UIView
orUIView
descendent can be added to any otherUIView
as a subview. So you could create aUILabel
with your text and add it as a subview to yourUIImageViews
using an appropriateCGRect
for theUILabel
's frame to position it where you want it in yourUIImageView
.您可以子类化 UIImageview 并添加 UILabel 作为子视图。然后您可以编辑标签,它会无缝地工作。
You could subclass UIImageview and add a UILabel as a subview. Then you can edit the label and it would work seamlessly.