swift3

Autolayouts : How to create collapse/Expand dynamic view swift 3/4

一世执手 提交于 2020-08-20 19:00:17
问题 I have a problem that I can't create a view that can collapse it's contents that may be dynamic height , i know it's easy to collapse it with height constant = 0 , but i can't figure out how to make it expand again as the content of that view is dynamic and sub-itmes may be added later I want that behavior 回答1: Your answer has massively overcomplicated a very simple solution. You should first create your zeroHeightConstraint as a property. let zeroHeightConstraint: NSLayoutConstraint =

Type Any has no subscript members json Swift 3

允我心安 提交于 2020-08-06 04:38:37
问题 I have this code: let subjectAbbreviation = JSON?["data"]??["subject"]??["abbr"] as? String Swift 3 complains: Type Any has no subscript members How would I unwrap this? I know I can use (JSON as? AnyObject) seems kind of messy though. 回答1: You need to specify the type of your json to [String: Any] so try like this. if let jsondata = json as? [String: Any], let data = jsondata["data"] as? [String: Any], let subject = data["subject"] as? [String: Any], let addr = subject["subject"] as? String

Type Any has no subscript members json Swift 3

梦想与她 提交于 2020-08-06 04:38:15
问题 I have this code: let subjectAbbreviation = JSON?["data"]??["subject"]??["abbr"] as? String Swift 3 complains: Type Any has no subscript members How would I unwrap this? I know I can use (JSON as? AnyObject) seems kind of messy though. 回答1: You need to specify the type of your json to [String: Any] so try like this. if let jsondata = json as? [String: Any], let data = jsondata["data"] as? [String: Any], let subject = data["subject"] as? [String: Any], let addr = subject["subject"] as? String

Swift Change the tableviewcell border color according to data

我与影子孤独终老i 提交于 2020-08-04 03:39:29
问题 I have written a code for making the cell border color change according to inStock or outStock , if it is inStock it will be red border else it would be green, but I it is not working for me, I put it in willDisplayCell and here is my code : func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath){ cell.backgroundColor = UIColor.clear cell.contentView.backgroundColor = UIColor.clear let whiteRoundedView : UIView = UIView(frame: CGRect(x:10,y:

Swift Change the tableviewcell border color according to data

核能气质少年 提交于 2020-08-04 03:39:09
问题 I have written a code for making the cell border color change according to inStock or outStock , if it is inStock it will be red border else it would be green, but I it is not working for me, I put it in willDisplayCell and here is my code : func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath){ cell.backgroundColor = UIColor.clear cell.contentView.backgroundColor = UIColor.clear let whiteRoundedView : UIView = UIView(frame: CGRect(x:10,y:

Add a gradient on UIImageView

徘徊边缘 提交于 2020-07-28 13:04:26
问题 I am trying to add a sublayer on my UIImageView but it doesn't work. I have a set of 10 images named from photo0 to photo9 and I display it with a timer of 5s. The outlet shanghaiImage is my background I would like to add a gradient on top of this marty like: transparent (top) to black (bottom). Thanks for the help :) Here is my code in Swift 3. This part is fine : import UIKit class ViewController: UIViewController { @IBOutlet weak var shanghaiImage: UIImageView! // beginning index var

Add a gradient on UIImageView

落爺英雄遲暮 提交于 2020-07-28 13:04:22
问题 I am trying to add a sublayer on my UIImageView but it doesn't work. I have a set of 10 images named from photo0 to photo9 and I display it with a timer of 5s. The outlet shanghaiImage is my background I would like to add a gradient on top of this marty like: transparent (top) to black (bottom). Thanks for the help :) Here is my code in Swift 3. This part is fine : import UIKit class ViewController: UIViewController { @IBOutlet weak var shanghaiImage: UIImageView! // beginning index var

Correctly chain multiple promises in PromiseKit 6

落爺英雄遲暮 提交于 2020-07-21 10:20:51
问题 I'm using Promisekit 6 and have 3 functions defined, all of which return promises. the first fetches data from a local database and the second from an online API server. the third, Foo, checks if the data with a given id exists locally, otherwise it checks online and returns it. I'm having trouble figuring out how to correctly chain the promises. Below is what I came up with thus far, but I'm not certain if creating a new promise is a good idea. Any feedback is appreciated. Thanks :) func

Setting becomeFirstResponder on viewController nested in PageViewController

你离开我真会死。 提交于 2020-06-28 06:22:15
问题 I have a pageViewController that has two child view controllers that you can swipe between. One of them has a textView that I want to be the first responder when you scroll onto that page, then lose focus when you scroll away. Right now I have this: override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) composeTextView.delegate = self composeTextView.becomeFirstResponder() } The keyboard shows up as soon as you start to scroll onto the view. But as soon as the

iOS Charts X Axis labels are not all showing

混江龙づ霸主 提交于 2020-06-28 05:03:54
问题 My app manages the score of a sport that has 4 quarter periods. My bar chart will not display the x-axis labels correctly. It only shows Qtr 1 and Qtr 3, whereas it should show all 4 quarters under each respective pair of bars. Screen shot of Bar Chart func setChart(dataPoints: [String], values1: [Double], values2: [Double]) { let legend = barChartView.legend legend.enabled = true legend.textColor = Style.labelTextColor let xaxis = barChartView.xAxis xaxis.drawGridLinesEnabled = true xaxis