Post

Replies

Boosts

Views

Activity

Reply to UITableView display first 5 rows of an array
Just to get (slightly) more compact code: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell cell.cellLbl?.text = array[indexPath.row] cell.blurView.isHidden = indexPath.row 5 return cell }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to MeasurementFormatter preferred unit
Use .providedUnit : measurement = Measurement(value: 0.31, unit: UnitLength.centimeters) // Or measurement.convert(to: UnitLength.centimeters) formatter.unitOptions = [.providedUnit] print(formatter.string(from: measurement)) I tested the following: var formatter = MeasurementFormatter() formatter.locale = Locale(identifier: "fr-fr") var measurement = Measurement(value: 0.31, unit: UnitLength.meters) formatter.unitOptions = [.naturalScale] print(formatter.string(from: measurement)) measurement.convert(to: UnitLength.centimeters) formatter.unitOptions = [.providedUnit] print(formatter.string(from: measurement)) and got: 0,31 m 31 cm
Topic: App & System Services SubTopic: General Tags:
May ’21
Reply to Sort is swift doubles the number of entries in array
Please format the code with tool: class InventoryModel: ObservableObject { @Published var fileData = [inventoryEntry]() var fileData2 = [inventoryEntry]() // for debug viewing fileData var fileData3 = [inventoryEntry]() // for debug viewing fileData // ..... } struct inventoryEntry { var id: UUID = UUID() var name: String = "" var catagory: String = "" var subcatagory: String = "" var location: String = "" } Could you show more code ? inventoryModel.fileData.sort{$0.name $1.name}
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Adding border colour to page control applies background colour to page control
slideControl.customPageControl(dotFillColor: UIColor(named: "Primary-Color")!, dotBorderColor: UIColor(named: "Primary-Color")!, dotBorderWidth: CGFloat(2)) Which color do you expect, as you call for the same UIColor(named: "Primary-Color") Did you try with something like: slideControl.customPageControl(dotFillColor: UIColor.blue, dotBorderColor: UIColor.red, dotBorderWidth: CGFloat(2))
Topic: UI Frameworks SubTopic: UIKit Tags:
May ’21
Reply to Adding border colour to page control applies background colour to page control
I would like to check a few points in this func : func customPageControl(dotFillColor:UIColor, dotBorderColor:UIColor, dotBorderWidth:CGFloat) { for (pageIndex, dotView) in self.subviews.enumerated() { if self.currentPage == pageIndex { dotView.backgroundColor = dotFillColor dotView.layer.cornerRadius = dotView.frame.size.height / 2 }else{ dotView.backgroundColor = .white dotView.layer.cornerRadius = dotView.frame.size.height / 2 dotView.layer.borderColor = dotBorderColor.cgColor dotView.layer.borderWidth = dotBorderWidth } } } You do not reset colors when it's not the current page. Why ? you set corner radius in all cases, that could be outside the if. More critical, pageControl has only one subview (each dot is not a subview). So what do you expect with: for (pageIndex, dotView) in self.subviews.enumerated() { } I would try the following: func customPageControl(dotFillColor:UIColor, dotBorderColor:UIColor, dotBorderWidth:CGFloat) { for (pageIndex, dotView) in self.subviews.enumerated() { print("pageIndex", pageIndex) // You should get only 0 dotView.layer.cornerRadius = dotView.frame.size.height / 2 dotView.layer.borderWidth = dotBorderWidth if self.currentPage == pageIndex { dotView.backgroundColor = dotFillColor.cgColor // in case you need cgColor dotView.layer.borderColor = // any color you need } else { dotView.backgroundColor = .white dotView.layer.borderColor = dotBorderColor.cgColor } } } To get what you want, you may need to create your custom pageControl or use those 2 func: The first would be the filled dot, the other the empty dot. var preferredIndicatorImage: UIImage? The preferred image for indicators. func setIndicatorImage(UIImage?, forPage: Int) Sets the indicator image for the specified page.
Topic: UI Frameworks SubTopic: UIKit Tags:
May ’21
Reply to GCD running background thread in spritekit
Where does it crash exactly ? In moveBox ? I do not understand wheree you add a node here. Looking at the crash report, I would do differently to enumerate the array: func moveBox() { for i in 0..boxArray.count { if var box = self.childNode(withName: "\(boxArray[i])") as? SKSpriteNode { // Need also to test it can be cast to SKSpriteNode box.position.x += 10 } } }
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Managing External Subviews and Layout
Why don't you create the splitView in IB ? With 2 subviews, which are A and B. Then in the viewDidLoad of the splitView or even in applicationDidFinishLaunching, you can insert any object like this (to insert a dummy button in the first view (A for you if I understand well)): let button = NSButton(title: "New", target: self, action: nil) button.frame = CGRect(x: 20, y: 120, width: 100, height: 20) (self.splitView.subviews[0] as! NSScrollView).contentView.addSubview(button) With the same pattern, you can instantiate viewA and viewB and add them to the corresponding subview of the splitView. For the constraints, you can define them in the nib or programmatically (you should subclass NSScrollView for A and B to connect to the IBOutlets in that case). This is Swift, but you should have no problem to write it in objC. If that answers your question, don't forget to close the thread by marking this answer as correct. Otherwise, please explain the remaining problem.
Topic: UI Frameworks SubTopic: AppKit Tags:
May ’21