Skip to content

Instantly share code, notes, and snippets.

View lamb-mei's full-sized avatar

羊小咩 lamb-mei

  • Taiwan / Taipei
View GitHub Profile
@megimix
megimix / UIImageView+topAlignmentAndAspectFit
Last active June 14, 2022 09:01
UIImageView with Aspect Fit and Alignment To Top. thanks to (http://stackoverflow.com/a/27569222/1267174)
extension UIImageView {
func topAlignmentAndAspectFit(to view: UIView) {
self.contentMode = .scaleAspectFill
self.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(self)
self.addConstraints(
[NSLayoutConstraint(item: self,
attribute: .height,
relatedBy: .equal,