- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试创建下图的可调整大小版本(40x28,底部的小三角形应水平居中):
UIEdgeInsets imageInsets = UIEdgeInsetsMake(4.0f, 4.0f, 8.0f, 4.0f);
UIImage *pinImage = [[UIImage imageNamed:@"map_pin"] resizableImageWithCapInsets:imageInsets];
根据 documentation ,这种简单的方法将不起作用,因为我的三角形落入可调整大小的区域(固定高度但可缩放宽度):
这将导致与 this 中描述的问题相同非常相似的 SO 后 - 重复(平铺)三角形。但不幸的是,他们的解决方案不适用于我的特殊情况,因为从可缩放区域中排除三角形会导致其错位并且由于明显的原因它不会水平居中。
所以我想知道...是否有可能使用 [UIImage resizableImageWithCapInsets:]
方法实现我的目标?还是我应该尝试其他方法,例如在代码中绘制所有内容?
基本上,我想从 Google Maps SDK 中实现信息窗口之类的东西:
最佳答案
您可以通过使用 UIBezierPath
来实现。下面的代码在 swift 中,但您应该能够在 Objective-C 中实现同样的事情
而不是用直线开始代码:
path.moveToPoint(CGPoint(x: 300, y: 0))
我改为从弧线开始(右上角):
path.addArcWithCenter(CGPoint(x: 300-10, y: 50), radius: 10 , startAngle: 0 , endAngle: CGFloat(M_PI/2) , clockwise: true) //1st rounded corner
通过这样做,我得到了四个圆角,我只需要在之前的代码末尾添加一条直线:
path.closePath()
这是代码和截图:
let path = UIBezierPath()
path.addArcWithCenter(CGPoint(x: 300-10, y: 50), radius: 10 , startAngle: 0 , endAngle: CGFloat(M_PI/2) , clockwise: true) //1st rounded corner
path.addArcWithCenter(CGPoint(x: 200, y: 50), radius:10, startAngle: CGFloat(2 * M_PI / 3), endAngle:CGFloat(M_PI) , clockwise: true)// 2rd rounded corner
path.addArcWithCenter(CGPoint(x: 200, y: 10), radius:10, startAngle: CGFloat(M_PI), endAngle:CGFloat(3 * M_PI / 2), clockwise: true)// 3rd rounded corner
// little triangle
path.addLineToPoint(CGPoint(x:240 , y:0))
path.addLineToPoint(CGPoint(x: 245, y: -10))
path.addLineToPoint(CGPoint(x:250, y: 0))
path.addArcWithCenter(CGPoint(x: 290, y: 10), radius: 10, startAngle: CGFloat(3 * M_PI / 2), endAngle: CGFloat(2 * M_PI ), clockwise: true)
path.addLineToPoint(CGPoint(x:300 , y:50))
path.closePath()
关于ios - 复杂图像(气泡/图钉)和 [UIImage resizableImageWithCapInsets :],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38875805/
我想绘制一个 Bing map ,它采用纬度和经度值并在 map 上绘制图钉。目前我只是使用一些测试数据,因为我才刚刚开始学习 API。下面的代码绘制了一张 map ,但没有向其中添加任何图钉。我似乎
我正在开发一个包含 MapKit 的应用程序。当第一张 map 加载时,pin 将位于预定义的位置。而此时pin的draggable属性设置为NO。现在我想做这个..当用户按下按钮编辑时,它将允许用户
我有一个条件语句,可以在下面的方法中添加 map 注释图标/图钉。我遇到的问题是 map 上填充了所有相同的图标。它应该检测猫 ID 并根据检测到的猫 ID 显示图标。我不确定问题出在哪里,因为这在
我正在制作一个 iOS 应用程序,用户可以在其中放置一个图钉 (CLLocation) 在 map 上,并且该点 x 英里范围内的所有其他用户都可以在 map 上看到它。我怎样才能做到这一点? 最佳答
我有一个 map 应用程序,当用户移动到某些位置时,它会插入 map 图钉,我的问题是如何计算用户经过或去过同一地点的次数。 在以下示例中有: 用户已到过地点 A (纬度、经度)五次。 这是我到目前为
这里我有两个观点: WallViewController TableViewController WallViewController 包含 MKMapView,TableViewController
在 MKMapView 上,您可以显示用户位置。蓝色用户位置点周围是一种“蓝色光环”,代表准确性。如何将它添加到我自己的应用程序中,但围绕一个引脚? pin 的位置来自那里使用 CoreLocatio
我一直在尝试制作一个应用程序,当按下标记调查结果按钮时, map 图钉会在用户的当前位置弹出。 问题是,每当我在 IBAction 中调用 DidUpdateLocations 时, map 注释永远
我有这个代码可以在谷歌地图上显示多个地址。 问题是,当页面首次加载时, map 显示蓝色的大海并且不对地址进行地理编码,我想它正在使用 0,0 的经纬度。 当我重新加载页面时,它会找到地址并将其显示在
我有一个带有大量图钉的 map View ,每个图钉都有唯一的注释。该 map 还显示了用户位置的脉动蓝点。到目前为止,我只能确定是否触摸了一个引脚,但不能确定被触摸的特定引脚。 如何确定用户触摸的
我正在尝试创建一个搜索栏,用于过滤掉列表中与搜索查询不匹配的项目。我试图添加的附加功能是,如果它与搜索查询不匹配,它也会从 map 中删除图钉。 这就是我现在拥有的,它适用于删除页面顶部的名称,但我喜
我是 Maps Concept 的新手。 请一次找到所附图片。 当我单击“图钉”时,我收到的消息是“欣赏你的微笑”或任何文字......现在我想......当我们选择表格 View 时,我需要为此提出
我在我的应用程序中使用谷歌地图 api。我的应用程序中有两个按钮。第一个按钮在我的 map 中添加了一个标记(图钉)。 现在我想要第二个按钮将添加的图钉水平移动到页面中心,并使其移动到页面顶部的 25
我正在尝试创建一个自定义引脚,该引脚的中心有一个标签,该标签会随每个引脚而变化。标签只是引脚编号,因此如果我有 8 个引脚,每个引脚都会在中心有一个数字,即第一个引脚将有 1,第二个引脚将有 2,依此
我正在尝试显示带有坐标数组的 map View 。所以,我从包含这些的数组中加载纬度和经度。它显示完美。现在,我想用不同的颜色图钉显示一个特定的纬度和经度。我提到了this answer我看不出有什么
服务器响应每 5 秒更新一次坐标。我将这个坐标像图钉一样添加到 map 中。但是当前对象的现有坐标不会删除,它只是添加为新坐标。如何更新当前对象的坐标并删除暂时没有坐标的对象? 我使用原生 map 。
在我的应用程序中,我使用 json 从 Web 服务下载一组点。将应用程序实现到 iOS7,我正在试验这个问题:位置已下载,但在用户触摸并“移动” map 之前不会绘制 map 上的图钉。然后它们出现
我知道这是一个经常被问到的问题。一段时间以来,我一直在阅读这里的许多问题。我希望有人能有一种更简单的方法,使用我必须用图像替换 map 上的图钉的代码。我对 objective-c 还是很陌生。我的代
mapbox 的文档中有两个相关示例: Change Marker Color on Click和 Draggable Marker 但是他们以非常不同的方式创建标记。 方法A: 在“单击时更改标记颜
我正在将注释加载到我的 map View 上。加载 map 时,注释显示为图钉。 但是,标题和副标题不会自动出现在图钉上。目前,用户需要在标题显示之前点击图钉。 有没有办法让标题在加载 map 时自动
我是一名优秀的程序员,十分优秀!