Can't seem to find what kind of component this is in Apple HIG. Would appreciate the answers!
Replies
what kind of component this is
What do you mean precisely ?
- The alert ?
- the heart icon ?
- something else ?
To achieve something similar, you could :
- set alert title to emoji heart in Symbols (choose color)
- set font and size:
let myFont = UIFont(name: "AppleColorEmoji", size: 128)
var attributes = [ NSAttributedString.Key: Any ] ()
attributes[NSAttributedString.Key.font] = myFont
let myTitle = NSMutableAttributedString(string: "\n", attributes: attributes16)
myTitle.append(NSMutableAttributedString(string: "♥︎", attributes: attributes))
You could also use heart SF symbol and insert in alert:
let heartImage = UIImage(systemName: "heart")
var imageView = UIImageView(frame: CGRect(x: 40, y: 10, width: 80, height: 80))
imageView.image = heartImage
alert.view.addSubview(imageView)
Sorry for didn't make it clear earlier.
I meant the whole UI component which is often used for indicating some feedback to users. e.g when Xcode build fails, it shows with a message "Build failed". Some folks name this "CenterAlert" but no luck with it and it's not even documented in the Apple HIG. Hope that I made myself clear : ).
UI component which is often used for indicating some feedback to users
I hope I understand your question now. That is what alerts are for.
With code such as:
let myFont = UIFont(name: "AppleColorEmoji", size: 128)
var attributes = [ NSAttributedString.Key: Any ] ()
attributes[NSAttributedString.Key.font] = myFont
let myTitle = NSMutableAttributedString(string: "\n", attributes: attributes16)
myTitle.append(NSMutableAttributedString(string: "♥︎", attributes: attributes))
let alert = UIAlertController(title: "", message: "Love\nWe'll recommend more for you", preferredStyle: .alert)
alert.setValue(myTitle, forKey: "attributedTitle")
If you have no button in alert, you must dismiss it when tapping somewhere outside. https://stackoverflow.com/questions/31857137/how-to-programmatically-dismiss-uialertcontroller-without-any-buttons
That’s often called a HUD or heads-up display.
Here’s one library that implements that sort of thing: https://github.com/jdg/MBProgressHUD
-
Thanks a lot. I think that's it.