Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 641 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change a SF Symbol size inside a UIButton

#1
I am declaring a Button like this :

let menuButton = UIButton()

After that I am trying to change it's parameter and set his position on the view with the help of LBTATools (a pod) with this function:

fileprivate func setMenuButtonUI() {
menuButton.setImage(UIImage(systemName: "line.horizontal.3.decrease.circle.fill"), for: .normal)
view.addSubview(menuButton)
menuButton.anchor(top: view.safeAreaLayoutGuide.topAnchor, leading: view.leadingAnchor, bottom: nil, trailing: nil, padding: .init(top: 20, left: 60, bottom: 0, right: 0), size: .init(width: 40, height: 40))
menuButton.setupShadow(opacity: 1, radius: 5, offset: .zero, color: .darkGray)
menuButton.tintColor = .red
}

Everything is working well, I get the right color, position and even size.
Only problem is it's size, I cannot change it with all the usual methods like `menuButton.imageView?.contentMode = .scaleAspectFit` etc..

Probably it comes from the fact that it is a SF Symbol and not a normal image.

The help of someone would be really appreciated.

Thanks
Reply

#2
The iOS 15 and Swift 5 solution would be:

```
var config = UIButton.Configuration.plain() // Change style with e.g. `.filled()`
config.title = "Title of the UIButton"
config.image = UIImage(systemName: "line.horizontal.3.decrease.circle.fill",
withConfiguration: UIImage.SymbolConfiguration(scale: .small)) // Change the scale here
config.imagePadding = 4 // Padding between image and title

let menuButton = UIButton()
menuButton.configuration = config
```
Reply

#3
Objective C:

UIImageSymbolConfiguration * configuration = [UIImageSymbolConfiguration configurationWithPointSize:30 weight:UIImageSymbolWeightBold scale:UIImageSymbolScaleLarge];
UIImage * image = [UIImage systemImageNamed:@"" withConfiguration:configuration];
[_btn setImage:image forState:UIControlStateNormal];
Reply

#4
You can do it using `SymbolConfiguration` like in the sample code below:

let largeConfig = UIImage.SymbolConfiguration(pointSize: 140, weight: .bold, scale: .large)

let largeBoldDoc = UIImage(systemName: "doc.circle.fill", withConfiguration: largeConfig)

button.setImage(largeBoldDoc, for: .normal)


[![enter image description here][1]][1]


[1]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through