Post

Replies

Boosts

Views

Activity

Reply to hello
You cannot change a button behaviour. That's forbidden. But to control brightness:         UIScreen.main.brightness = 0.1 // between 0 and 1
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Refreshing / Reloading Data of Supplementary View (Header & Footer) for Collection View
Here is the problem: line 8 you recreate a label and add it over if there is already an existing one: let headerUILabelText = UILabel() headerUILabelText.textAlignment = .left headerUILabelText.font = UIFont.systemFont(ofSize: 20, weight: .bold) headerUILabelText.numberOfLines = 0 headerUILabelText.text = "Your Roll Number is \(NumberInteger). Your Exam Numbers are \(examNumbers(number: "\(NumberInteger)"))" headerUILabelText.textColor = .darkGray headerUILabelText.lineBreakMode = .byTruncatingTail headerView.addSubview(headerUILabelText) You should either: remove subviews first test if there is already a UILabel and not recreate if so replace existing subview. I have used this extension: extension UIView { class func getAllSubviewsT: UIView(from parentView: UIView) - [T] { return parentView.subviews.flatMap { subView - [T] in var result = getAllSubviews(from: subView) as [T] if let view = subView as? T { result.append(view) } return result } } class func getAllSubviews(from parentView: UIView, types: [UIView.Type]) - [UIView] { return parentView.subviews.flatMap { subView - [UIView] in var result = getAllSubviews(from: subView) as [UIView] for type in types { if subView.classForCoder == type { result.append(subView) return result } } return result } } func getAllSubviewsT: UIView() - [T] { return UIView.getAllSubviews(from: self) as [T] } func getT: UIView(all type: T.Type) - [T] { return UIView.getAllSubviews(from: self) as [T] } func get(all type: UIView.Type) - [UIView] { return UIView.getAllSubviews(from: self) } } And call in your case: let allLabels = self.headerView.get(all: UILabel.self) for sub in allLabels { sub.removeFromSuperview() } And now you can safely add subview: headerView.addSubview(headerUILabelText)
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to hello
Please, explain what is your question take some care when you post code to make it easier to read: ZStack { LinearGradient(gradient: Gradient(colors: [Color.orange, Color.yellow, Color.white]), startPoint: .top, endPoint: .bottom) .edgesIgnoringSafeArea(.all) SwiftUIView() boton() .font(Font.system(size: 80)) .offset(x: 10, y: -10) } UIScreen.main.brightness = 0.1 // between 0 and 1 } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } what do you do with line 12, copied in the middle of the code ? It should be inside some func (like a Button action) what is boton() ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to How to animate a CATransform3DRotate ?
I see at least 2 ways: create a CoreAnimation with the transform keyPath let trans = CABasicAnimation(keyPath: "transform"); trans.fromValue = [0.0, 0.0, 1.0, 0.0] // you may have to correct this trans.toValue = [rotationAngle * .pi / 180.0, 0.0, 1.0, 0.0] // That's my guess of the correct set of parameters button.layer.add(cotransor, forKey: "rotation") // I am not sure of the keyPath to use For the list of keyPaths: https://stackoverflow.com/questions/44230796/what-is-the-full-keypath-list-for-cabasicanimation call animate on the view UIView.animate(withDuration: 2.0, delay: 0.0, options: .curveEaseOut, animations: { /* TRANSFORM */ }, completion: { (done) in } ) with the right animations and completion handler
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21