Auto Layout

RSS for tag

Create a user interface that dynamically responds to changes in the available screen space using Auto Layout.

Posts under Auto Layout tag

48 Posts
Sort by:
Post not yet marked as solved
4 Replies
1.7k Views
Hello! I have updated my project to Xcode 13 and iOS 15. Now the app is crashing with an error related to autoresizing masks in UITableViewCells. I have tried to change UITableViewCells Layer property in the inspector to Inferred and followed this post, but none of them are working. Have you encountered this problem. How it could be fixed? Thanks 🙏
Posted Last updated
.
Post not yet marked as solved
2 Replies
479 Views
There are two problems which have an one root. I present ViewController modally and it has UITextView in ScrollView, when I call dismiss it, right after that, the text on UITextView is erasing This bug affects on following solution, describing here https://stackoverflow.com/questions/50011682/handling-scroll-views-with-custom-interactive-view-controller-presentation-an And If I uncomment following code, and use Custom modal transition, describing on article above, I will get that every time when I touch the ChildViewController and moving the finger, the UITextView will be empty on screen, and when I unthouch screen, the text will be shown on screen. class ChildViewController: UIViewController {     private let descriptionTextView: UITextView = {         let tv = UITextView()         tv.font = .systemFont(ofSize: 15)         tv.isSelectable = true         tv.textContainer.lineFragmentPadding = .zero         tv.textContainerInset = .zero         tv.isEditable = false         tv.isScrollEnabled = false         tv.isUserInteractionEnabled = true         tv.dataDetectorTypes = .link         tv.bounces = false         tv.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         tv.text = "There are two view controllers: ViewController and TextViewController. Both view controllers are showing a UITextView and a button. I've created a segue called \"textSegue\" when I press the \"Text\" button on the ViewController the text is passed to the TextViewController and displayed. On the TextViewController I can select the text and press the 'Bold' button to make the text bold. When I press the \"Back\" button, the TextViewController is dismissed and the ViewController will show the attributed text. The problem is, when I press the \"Text\" button again and the TextViewController shows, the text in the UITextView doesn't show the attributed text (it is'n bold anymore)."         tv.translatesAutoresizingMaskIntoConstraints = false         return tv     }()     private lazy var scrollView: UIScrollView = {         let scrollView = UIScrollView()         scrollView.bounces = false         scrollView.translatesAutoresizingMaskIntoConstraints = false         scrollView.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         return scrollView     }()     override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = UIColor(hue: 0.2, saturation: 0.8, brightness: 0.9, alpha: 1)         view.layer.cornerRadius = 24         view.addSubview(scrollView)         scrollView.addSubview(descriptionTextView)         addDismissButton()         NSLayoutConstraint.activate([             scrollView.topAnchor.constraint(equalTo: view.topAnchor, constant: 24),             scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),             scrollView.leftAnchor.constraint(equalTo: view.leftAnchor),             scrollView.rightAnchor.constraint(equalTo: view.rightAnchor),             descriptionTextView.topAnchor.constraint(equalTo: scrollView.topAnchor),            descriptionTextView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),             descriptionTextView.leftAnchor.constraint(equalTo: scrollView.leftAnchor),             descriptionTextView.rightAnchor.constraint(equalTo: scrollView.rightAnchor),             descriptionTextView.widthAnchor.constraint(equalTo: scrollView.widthAnchor),         ])     }     private func addDismissButton() {         let button = UIButton(type: .system)         button.setTitle("Dismiss", for: .normal)         button.addTarget(self, action: #selector(dismissSelf), for: .touchUpInside)         view.addSubview(button)         button.translatesAutoresizingMaskIntoConstraints = false         NSLayoutConstraint.activate([             button.centerXAnchor.constraint(equalTo: view.centerXAnchor),             button.bottomAnchor.constraint(equalTo: view.bottomAnchor),             button.widthAnchor.constraint(equalToConstant: 200),             button.heightAnchor.constraint(equalToConstant: 80),             ])     }         @objc func dismissSelf() {         self.dismiss(animated: true)     } } class ParentViewController: UIViewController {     private let transition = PanelTransition()     @IBAction func openDidPress(_ sender: Any) {         let child = ChildViewController() //        child.transitioningDelegate = transition //        child.modalPresentationStyle = .custom         child.modalPresentationStyle = .fullScreen                present(child, animated: true)     } } And If I uncomment following code child.transitioningDelegate = transition child.modalPresentationStyle = .custom, and use Custom modal transition, describing on article above, I will get that every time when I touch the ChildViewController and moving the finger, the UITextView will be empty on screen, and when I untouch the screen, the text will be shown on screen. And I could catch this on View Debuger, and text is existing in UITextView, but on screen is not. Is It bug on UITextView?
Posted
by llodi.
Last updated
.
Post not yet marked as solved
2 Replies
309 Views
We have an application developed by one of our technology partners, to run with same behavior on both iOS and Android as an Authenticator mean used as one (out of 2) factor of authentication for PSD2 payments in Europe. The concept is that whenever the user is doing some action using a certain PSD2 compatible payment application (either from his mobile or thru the web) that needs to undergo a Strong Customer Authentication, he needs to authenticate himself using 2 factors, one of which is that he receives a push notification on his phone device hosting the said Authenticator app. When the push notification is pressed, the authenticator application appears on mobile screen with a message containing details about the PSD2 payment action being done (merchant name, amount, etc..). The user needs to press one of 2 buttons "Approve" or "Decline". Once he presses any one of these, the Authenticator application submits the response to its backend, and it should "automatically disappear" from the mobile screen once it informs its backend about the user's action (Approve or Decline); i.e. after the user presses one of the buttons, the Authenticator app should disappear in 1-2 seconds. We are not concerned how it disappears i.e. if the application closes itself (exiting), goes to background, suspend itself or any other method of hiding from display. The important is that the previous 3rd party payment application if running from same mobile device, it should be unveiled and re-appears on screen without any further action from the user. This is a mandate in PSD2 regulation. With Android we have no issue. With iOS, our vendor who developed the Authenticator app, says that Apple inhibits the automated disappearance of an iOS compatible application and that Apple will reject the app when it is submitted for review in case it does some sort of automatic exiting. From my readings, it seems yes Apple does not certify an auto-exit of an iOS app, however as said above, we just need to hide (with whatever way) the Authenticator automatically and unveil the 3rd party payment app (which can be any PSD2 compatible app for which we do not have any control to solicit it to bring itself to the foreground). Kindly advise on a solution. Thanks and regards,
Posted
by Mountazar.
Last updated
.
Post marked as solved
1 Replies
679 Views
I am trying to create a UIView within a UIStackView that I want to always be square regardless of device and orientation. I have seen posting that explain how others have done it (setting constraints between UIView and superview for both height and width - a required set and an optional set - along with a 1:1 aspect constraint for the UIView) , but it no longer seems to work under all instances - in particular iPad and iPhone 11s. Does anyone have any advice on how to make this happen. It seems to me to be a pretty routine thing to do. I've done it before programmatically, but I would really like to get it done within Interface Builder. Any suggestions would be greatly appreciated.
Posted Last updated
.
Post not yet marked as solved
8 Replies
2.7k Views
** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Not possible to remove variable: 400: unknown var (bug!) with engine as delegate:0x283c8ed40{id: 33112} colIndex:32 from engine NSISEngine: 0x129248130{ delegate:0x12934eaa0 EngineVars:  0: objective{id: 33102} rowIndex:0  1: UIImageView:0x12924ec90.Height{id: 32592} rowIndex:1073741824  2: 0x280a04be0.marker{id: 32591} colIndex:1073741825  3: UIImageView:0x12924ec90.Width{id: 32807} rowIndex:1  4: 0x280dc35a0.posErrorMarker{id: 32871} colIndex:1  5: 0x280dc35a0.negError{id: 32872} rowIndex:88  6: 0x280dc3d80.posErrorMarker{id: 32873} colIndex:1073741826  7: 0x280dc3d80.negError{id: 32874} rowIndex:1073741825  8: UIImageView:0x129353f00.Width{id: 32594} rowIndex:2  9: 0x280979d60.marker{id: 32593} colIndex:3 10: 0x280dc1e60.posErrorMarker{id: 32875} colIndex:4 11: 0x280dc1e60.negError{id: 32876} rowIndex:3 12: UIImageView:0x129353f00.Height{id: 32822} rowIndex:1073741826 13: 0x280dc39c0.posErrorMarker{id: 32877} colIndex:1073741827 14: 0x280dc39c0.negError{id: 32878} rowIndex:1073741898 15: UIButton:0x1293540d0.Width{id: 32817} rowIndex:4 16: 0x280dc2040.posErrorMarker{id: 32879} rowIndex:93 17: 0x280dc2040.negError{id: 32880} colIndex:6 18: UIButton:0x1293540d0.Height{id: 32820} rowIndex:1073741827 19: 0x280dc3de0.posErrorMarker{id: 32881} rowIndex:96 20: 0x280dc3de0.negError{id: 32882} colIndex:1073741830 21: UILabel:0x129353300.Width{id: 32811} rowIndex:5 22: 0x280dc3e40.posErrorMarker{id: 32883} colIndex:44 23: 0x280dc3e40.negError{id: 32884} rowIndex:90 24: UILabel:0x129353300.Height{id: 32842} colIndex:1073741828 25: 0x280dc27c0.posErrorMarker{id: 32885} colIndex:1073741831 26: 0x280dc27c0.negError{id: 32886} rowIndex:1073741828 27: UILabel:0x129353c90.Width{id: 32840} rowIndex:6 28: 0x280dc1da0.posErrorMarker{id: 32887} colIndex:9 29: 0x280dc1da0.negError{id: 32888} rowIndex:97 30: UILabel:0x129353c90.Height{id: 32829} colIndex:1073741832 31: 0x280dc31e0.posErrorMarker{id: 32889} colIndex:1073741833 32: 0x280dc31e0.negError{id: 32890} rowIndex:1073741900 33: UIImageView:0x12934e490.Width{id: 32596} rowIndex:1073741905 34: UIImageView:0x12934e490.Height{id: 32597} colIndex:1073741844 35: 0x280963a70.marker{id: 32595} colIndex:11 36: 0x280dc2ee0.posErrorMarker{id: 32891} colIndex:12 37: 0x280dc2ee0.negError{id: 32892} rowIndex:8 38: 0x280dc1d40.posErrorMarker{id: 32893} colIndex:1073741835 39: 0x280dc1d40.negError{id: 32894} rowIndex:1073741830 40: UIButton:0x1293543b0.Width{id: 32832} rowIndex:9 41: 0x280dc1440.posErrorMarker{id: 32895} colIndex:0 42: 0x280dc1440.negError{id: 32896} rowIndex:1073741845 43: UIButton:0x1293543b0.Height{id: 32827} rowIndex:1073741831 44: 0x280dc3840.posErrorMarker{id: 32897} colIndex:1073741836 45: 0x280dc3840.negError{id: 32898} rowIndex:1073741829 46: UILabel:0x129353a20.Width{id: 32848} rowIndex:10 and another thousand or so lines. this crash occurs after I change the language and open the workout page to start a workout immediately, and sometimes on the second time, I open the workout page.
Posted
by BibinAlex.
Last updated
.
Post not yet marked as solved
1 Replies
615 Views
I'm implementing a horizontal NSStackView with child views of varying size. The stack view should resize horizontally with its parent view, which in turn resizes with the window. I expect the stack view's arranged distribution (fill proportionally) to adjust the distribution of child views as its width changes. I keep hitting the bizarre behavior where the window can't be resized horizontally at all - the vertical/diagonal resize cursors no longer appear, and the window can only be resized vertically. The problem is not that the child view doesn't resize with the window: the child view actually prevents resizing of the window! I first saw this creating an empty NSStackView and adding it to its parent view in code, with layout constraints (top, leading, trailing; also tried width). I tried messing with constraint priorities but that did not correct the issue. (With the stack view not there, its parent view resizes with the window just fine). When I created the NSStackView in the .xib this problem went away, the empty NSStackView resizes horizontally along with its parent, so that's what I'm doing now. However, now when I add a set of arranged subviews in code, it happens again - they are distributed perfectly, but the window again cannot be horizontally resized! The subviews are minimal NSView implementations (drawing their bounds); they do not have intrinsic size. They do each have child NSTextField labels, with autolayout constraints to horizontally resize along with their parents. There are no constraints besides those internal to each child view and its label subview. What am I not understanding about AutoLayout and NSStackView? I cannot imagine an intentional design that would break the user's ability to resize the window in one direction based on anything an NSStackView does, but that's exactly what happens.
Posted
by ccorbell.
Last updated
.
Post not yet marked as solved
1 Replies
356 Views
My app loads an image at runtime and I want to display it inside a table cell. To do that I created a UIView (trailing/leading/top/bottom: 10) inside the cell and added a UIImageView as its child. What constraints do I need for the child, so the image keeps its proper aspect ration, isn't wider than the width of the screen and there's no unused space (apart from the constraints)? I tried to use: Trailing/leading/top/bottom: 0 Align center x/y This works if the image uses the portrait format but with landscape there's unused space above and below the image. I also tried to set the view's height to ">=50" but no success and I can't just set a max. value because my app has to work on both iPhones and iPads.
Posted
by Sim2019.
Last updated
.
Post not yet marked as solved
2 Replies
425 Views
Hey there, We're experiencing a big bump of these crashes with no great explanation. We're not doing anything special about the layout there except for using some nested Stack Views, and the view itself is embedded within a reusable cell. Attaching a full crash log - have plenty more of these but they are quite similar. Would appreciate your help :) Shai. 2021-10-20_11-48-29.1535_+0300-c0ce73e85344ddcdc178995f3e83de0b406bab54.crash
Posted Last updated
.
Post not yet marked as solved
2 Replies
332 Views
Hi. My 2 years old project shows ambiguous layout warnings after installing Xcode 13.0. The warnings are basically nuisance (layout shows correctly in the app). All the warnings refer to constraints of objects inside a tableview. The warnings start only after cell 16 downwards (distributed across 4 sections, S1: 2 cells, S2: 2 cells, S3: 1 cells, S4: 12 cells, ...). Hence my idea, if there is any limit to the number of cells Xcode 13.0 can handle? Previous Xcode didn't have any (!) issues regarding this portion of the layout. The screenshots just show an example of such a nuisance warning. Any ideas? Thanks.
Posted
by geohei.
Last updated
.
Post not yet marked as solved
0 Replies
293 Views
The ios app I am currently developing starts off on a login screen which then presents the next view controller via a login button. Upon moving on to the next VC I get the error: Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x600000d0af40 "UIStackView:0x7fe87df14160.top"> and <NSLayoutYAxisAnchor:0x600000d0ad40 "UILayoutGuide:0x600002102300'UIViewSafeAreaLayoutGuide'.bottom"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.' Here is the relevant VC code for the contoller being showed: class LocationSelectViewController: UIViewController {       let promptLabel: UILabel = {     let label = UILabel()           label.translatesAutoresizingMaskIntoConstraints = false     label.text = "Enter Your Location`s \nAddress"     label.font = .boldSystemFont(ofSize: 23)     label.numberOfLines = 0     label.preferredMaxLayoutWidth = label.frame.width     label.textAlignment = .center           return label   }()       let streetAddressField: UITextField = {     let textField = UITextField()         textField.translatesAutoresizingMaskIntoConstraints = false     textField.placeholder = "street address"     textField.borderStyle = .roundedRect     textField.textAlignment = .left         return textField   }()       let cityField: UITextField = {     let textField = UITextField()         textField.translatesAutoresizingMaskIntoConstraints = false     textField.placeholder = "city"     textField.borderStyle = .roundedRect     textField.textAlignment = .left         return textField   }()       let stateField: UITextField = {     let textField = UITextField()         textField.translatesAutoresizingMaskIntoConstraints = false     textField.placeholder = "state"     textField.borderStyle = .roundedRect     textField.textAlignment = .left         return textField   }()       let saveButton: UIButton = {     let button = UIButton(type: .system)     button.setTitle("Add Location", for: .normal)     button.translatesAutoresizingMaskIntoConstraints = false           return button   }()       var currentUser: User?   let geocoder = CLGeocoder()   override func viewDidLoad() {     super.viewDidLoad()           view.backgroundColor = .white           let stackView = UIStackView()           let views: [UIView] = [streetAddressField, cityField, stateField]           stackView.axis = .vertical     stackView.spacing = 17     stackView.translatesAutoresizingMaskIntoConstraints = false           view.addSubview(promptLabel)     view.addSubview(stackView)     view.addSubview(saveButton)           for view in views {       stackView.addArrangedSubview(view)     }           let constraintsArray: [NSLayoutConstraint] = [promptLabel.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), promptLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 30), promptLabel.heightAnchor.constraint(lessThanOrEqualToConstant: 70), stackView.topAnchor.constraint(equalTo: promptLabel.bottomAnchor, constant: 40), stackView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), stackView.widthAnchor.constraint(equalToConstant: 300), saveButton.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), saveButton.topAnchor.constraint(equalTo: stackView.bottomAnchor, constant: 30)]           saveButton.addTarget(self, action: #selector(addLocationTouchUpInside), for: .touchUpInside)           NSLayoutConstraint.activate(constraintsArray)   } Also I am aware that the constraints are hard to read so they are listed below promptLabel.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), promptLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 30), promptLabel.heightAnchor.constraint(lessThanOrEqualToConstant: 70), stackView.topAnchor.constraint(equalTo: promptLabel.bottomAnchor, constant: 40), stackView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), stackView.widthAnchor.constraint(equalToConstant: 300), saveButton.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor), saveButton.topAnchor.constraint(equalTo: stackView.bottomAnchor, constant: 30) I orginally asked this question on SO which has lead me to believe this is a potential bug. I likely could hold off or workaround the issue by rewriting/choosing different constraints, but if its a bug I would much rather not put in pointless work.
Posted Last updated
.
Post not yet marked as solved
5 Replies
2.0k Views
Using NSCollectionLayoutSize with .estimated dimensions in horizontal orthogonal sections, creates layout issues. The cells &amp; supplementary views have layout conflicts, the scroll behavior is sub optimal and spacing is not as expected Working with Xcode: 12.4 , Simulator: iOS 14.4 Layout bug: [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "NSLayoutConstraint:0x6000011266c0 UIView:0x7fc6c4617020.height == 80 (active)", "NSLayoutConstraint:0x600001126530 V:|-(0)-[UIView:0x7fc6c4617020] (active, names: '|':UIView:0x7fc6c4616d10 )", "NSLayoutConstraint:0x6000011261c0 UIView:0x7fc6c4617020.bottom == UIView:0x7fc6c4616d10.bottom (active)", "NSLayoutConstraint:0x600001121360 'UIView-Encapsulated-Layout-Height' UIView:0x7fc6c4616d10.height == 50 (active)" ) Will attempt to recover by breaking constraint NSLayoutConstraint:0x6000011266c0 UIView:0x7fc6c4617020.height == 80 (active) Code to reproduce: import UIKit class ViewController: UIViewController { lazy var collectionView: UICollectionView = { let layout = createLayout() let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView.translatesAutoresizingMaskIntoConstraints = false collectionView.dataSource = self collectionView.backgroundColor = .systemBackground collectionView.register(Cell.self, forCellWithReuseIdentifier: "cell") collectionView.register(HeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header") return collectionView }() private func createLayout() - UICollectionViewCompositionalLayout { let sectionProvider = { (section: Int, layoutEnvironment: NSCollectionLayoutEnvironment) - NSCollectionLayoutSection? in return self.horizontalLayout(layoutEnvironment: layoutEnvironment) } let config = UICollectionViewCompositionalLayoutConfiguration() config.interSectionSpacing = 8 let layout = UICollectionViewCompositionalLayout(sectionProvider: sectionProvider, configuration: config) return layout } private func supplementaryHeader() - NSCollectionLayoutBoundarySupplementaryItem { let titleSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(50)) let titleSupplementary = NSCollectionLayoutBoundarySupplementaryItem( layoutSize: titleSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top) return titleSupplementary } private func horizontalLayout(layoutEnvironment: NSCollectionLayoutEnvironment) - NSCollectionLayoutSection { let size = NSCollectionLayoutSize(widthDimension: .estimated(120), heightDimension: .estimated(50)) let item = NSCollectionLayoutItem(layoutSize: size) let group = NSCollectionLayoutGroup.horizontal(layoutSize: size, subitems: [item]) let section = NSCollectionLayoutSection(group: group) section.orthogonalScrollingBehavior = .continuous section.interGroupSpacing = 8 section.contentInsets = NSDirectionalEdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16) section.boundarySupplementaryItems = [supplementaryHeader()] return section } override func viewDidLoad() { super.viewDidLoad() view.addSubview(collectionView) NSLayoutConstraint.activate([ collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor), collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor), collectionView.topAnchor.constraint(equalTo: view.topAnchor), collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) } } // MARK: UICollectionViewDataSource extension ViewController: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) - UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) return cell } func numberOfSections(in collectionView: UICollectionView) - Int { return 25 } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) - Int { return 4 } func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) - UICollectionReusableView { switch kind { case UICollectionView.elementKindSectionHeader: let header: HeaderView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header", for: indexPath) as! HeaderView return header default: fatalError() } } } class Cell: UICollectionViewCell { lazy var view: UIView = { let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false view.backgroundColor = .systemRed return view }() override init(frame: CGRect) { super.init(frame: frame) configure() } required init?(coder: NSCoder) { fatalError("not implemented") } func configure() { contentView.addSubview(view) view.heightAnchor.constraint(equalToConstant: 80).isActive = true view.widthAnchor.constraint(equalToConstant: 100).isActive = true NSLayoutConstraint.activate([ view.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), view.topAnchor.constraint(equalTo: contentView.topAnchor), view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) ]) } } class HeaderView: UICollectionReusableView { lazy var view: UIView = { let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false view.backgroundColor = .systemTeal return view }() override init(frame: CGRect) { super.init(frame: frame) configure() } required init?(coder: NSCoder) { fatalError("not implemented") } func configure() { addSubview(view) view.heightAnchor.constraint(equalToConstant: 60).isActive = true NSLayoutConstraint.activate([ view.leadingAnchor.constraint(equalTo: self.leadingAnchor), view.trailingAnchor.constraint(equalTo: self.trailingAnchor), view.topAnchor.constraint(equalTo: self.topAnchor), view.bottomAnchor.constraint(equalTo: self.bottomAnchor) ]) } }
Posted
by papanton.
Last updated
.
Post not yet marked as solved
0 Replies
246 Views
This is really a post (dig at) to the SwiftUI designers. I have been a developer in many many different languages for far too many years. Over the last 20 I have done a lot of web (browser) development. From the web developer perspective, developing applications that behave correctly in any browser has been a really big thing for probably more than 20 years. I even remember doing it in tables. We are now at a stage where it does work now (mostly). Frameworks like Twitter Bootstrap work really well and so do a lot of others. Their basic mission is that a page (view) will work no matter what the resolution (even those we don’t have yet) in an ever changing ‘view’ world. Yet I now come to SwiftUI… Lots of tell us your device and get your graphic designer to produce a zillion graphics for each (noting he / she isn’t a fortune teller, so they do not know what’s coming next. After playing for days with GeometryReader and UIScreen.main.bounds (hell will that even be supported in the future) I’m not impressed. I don’t understand why something that has been analysed and pretty much put to bed in the ‘web’ world is now attempting to be reinvented really really really really badly. I even attempted to fix this issue with UIKit but even that wasn’t much better.  Why is a company with so much money and so many resources trying to reinvent the wheel? I don’t get it. So much so I’m starting to tell my clients (big ones) to ditch Apple and go down far easier roots. I doubt any of the SwiftUI compiler developers even read this stuff. But hey if you do, it’s time for a reality check… If they don’t ha ha ha ha I rest my case.
Posted Last updated
.
Post marked as solved
3 Replies
569 Views
Hello! I am new to iOS development and was walking through UIKit iOS App Dev Tutorial on this website. My problems start every time when I need to set leading horizontal spacing to "Standard" by removing value or selecting it in the dropdown menu. When I try to do that, the value in the field resets to previously set value and "Use Standard value" is greyed out. This is so frustrating! Even when I download complete project and try to set value myself, it still does not work! Is it an Xcode bug? My version is 13.0 (13A233)
Posted Last updated
.
Post not yet marked as solved
1 Replies
863 Views
Hello! I am having trouble with my quiz game - sometimes (not always) after completing a level, the screen darkens and the game becomes unresponsive. I am unable to click anywhere on the screen. I've been scratching my head about this issue for several weeks now and can't get to the bottom of it. I'd really appreciate some help/advice on the matter if anyone knows that's wrong. I've attached the error log as it was too long to add here. Many thanks, Ermes Error log:
Posted Last updated
.
Post not yet marked as solved
1 Replies
374 Views
I'm using boundingRect to calculate the height of a String, I'm using Ubuntu as my font, and when I supply .usesFontLeading as one of the options alongside .usesLineFragmentOrigin the height is completely different to what I expect. Here is the code I'm using for reference: func height(withConstrainedWidth width: CGFloat, font: UIFont, maxLines: CGFloat = 0) -> CGFloat {         let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)         let boundingBox = self.boundingRect(with: constraintRect, options: [.usesFontLeading, .usesLineFragmentOrigin], attributes: [             NSAttributedString.Key.font: font         ], context: nil)         var size = boundingBox.size         if maxLines > 0 {             size.height = min(size.height, CGFloat(maxLines) * font.lineHeight)         }         return ceil(size.height)     } Firstly, what does .usesFontLeading even do, and why is it that the result I'm getting an unexpected result. Note: self is String because I've extended the String class.
Posted Last updated
.