我正在尝试将地图引脚的名称存储在变量中,然后将其显示在我的第二个VC上的标签上.
目前,这就是我所拥有的.
FirstVC.swift
//Perform segue when callout has been tapped
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
self.performSegue(withIdentifier: "showAnnotationInfo", sender:view)
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
print("Annotation selected")
if let annotation = view.annotation as? POIAnnotations {
print("Your annotation title is: \(annotation.title!)")
// Instantiate ShopDetailViewController
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destVC = storyboard.instantiateViewController(withIdentifier: "shopDetailVC") as! ShopDetailViewController
destVC.shopNameData = annotation.title!
print("Shop name data has the value: \(destVC.shopNameData)")
}
}
Run Code Online (Sandbox Code Playgroud)
ShopDetailViewController.swift
class ShopDetailViewController: …Run Code Online (Sandbox Code Playgroud) 我是Swift的新手,我正试图改变按钮颜色.当点击按钮时,它应该改变颜色,当释放时它应该回到原始按钮颜色.
一个例子是计算器.当您点击一个按钮时,它会从浅灰色变为深灰色,当用户将手指从按钮上移开时,它会恢复为原始的浅灰色.我该怎么做呢?
到目前为止,我只有这个..
@IBAction func changeButtonColourOnTouch(sender: UIButton) {
zeroButton.backgroundColor = UIColor.blueColor()
}
Run Code Online (Sandbox Code Playgroud)
上面的代码将按钮颜色更改为蓝色但保持蓝色.
当我在故事板中时,导航栏标题在故事板中默认显示为粗体,但是当您在模拟器和设备中运行应用程序时,它不是粗体.令人讨厌的是,无法从界面构建器更改字体大小.
您可以在下面看到界面构建器和模拟器上显示的内容之间的区别.
我知道我可以使用类似的东西更改字体:self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "YOUR-FONT-NAME-WEIGHT", size: 24)!
这将是完美的但我想将字体保持为默认的SF字体.
有解决方法吗?出现这种情况的原因是什么
我正试图通过该函数将数据传递给我的第二个VC上的标签func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView).
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
print("Annotation selected")
if let annotation = view.annotation as? POIAnnotations {
let destVC : ShopDetailViewController
destVC.shopName.text = annotation.title!
print("Your annotation title is: \(annotation.title!)")
}
}
Run Code Online (Sandbox Code Playgroud)
当我设置shopName.text为annotation.title,我得到一个错误说明:
在初始化之前使用常量'destVC'.
我不太清楚出了什么问题.