Skip to content

Commit

Permalink
[Set/#1] extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe0929 committed Dec 29, 2023
1 parent 631181b commit 1deb723
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 4 deletions.
56 changes: 55 additions & 1 deletion HMH_iOS/HMH_iOS/Global/Extension/Adjust+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,58 @@
// Created by 지희의 MAC on 12/29/23.
//

import Foundation
import UIKit

extension CGFloat {
var adjusted: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.width / 375
let ratioH: CGFloat = UIScreen.main.bounds.height / 667
return ratio <= ratioH ? self * ratio : self * ratioH
}

var adjustedWidth: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.width / 375
return CGFloat(self) * ratio
}

var adjustedHeight: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.height / 667
return CGFloat(self) * ratio
}
}

extension Int {
var adjusted: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.width / 375
let ratioH: CGFloat = UIScreen.main.bounds.height / 667
return ratio <= ratioH ? CGFloat(self) * ratio : CGFloat(self) * ratioH
}

var adjustedWidth: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.width / 375
return CGFloat(self) * ratio
}

var adjustedHeight: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.height / 667
return CGFloat(self) * ratio
}
}

extension Double {
var adjusted: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.width / 375
let ratioH: CGFloat = UIScreen.main.bounds.height / 667
return ratio <= ratioH ? CGFloat(self) * ratio : CGFloat(self) * ratioH
}

var adjustedWidth: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.width / 375
return CGFloat(self) * ratio
}

var adjustedHeight: CGFloat {
let ratio: CGFloat = UIScreen.main.bounds.height / 667
return CGFloat(self) * ratio
}
}
14 changes: 13 additions & 1 deletion HMH_iOS/HMH_iOS/Global/Extension/UIButton+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@
// Created by 지희의 MAC on 12/29/23.
//

import Foundation
import UIKit

extension UIButton {
func setUnderline() {
guard let title = title(for: .normal) else { return }
let attributedString = NSMutableAttributedString(string: title)
attributedString.addAttribute(.underlineStyle,
value: NSUnderlineStyle.single.rawValue,
range: NSRange(location: 0, length: title.count)
)
setAttributedTitle(attributedString, for: .normal)
}
}
31 changes: 30 additions & 1 deletion HMH_iOS/HMH_iOS/Global/Extension/UILabel+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,33 @@
// Created by 지희의 MAC on 12/29/23.
//

import Foundation
import UIKit

extension UILabel {
func asColor(targetString: String, color: UIColor?) {
let fullText = text ?? ""
let attributedString = NSMutableAttributedString(string: fullText)
let range = (fullText as NSString).range(of: targetString)
attributedString.addAttributes([.font: font as Any, .foregroundColor: color as Any], range: range)
attributedText = attributedString
}

func setTextWithLineHeight(text: String?, lineHeight: CGFloat) {
if let text = text {
let style = NSMutableParagraphStyle()
style.maximumLineHeight = lineHeight
style.minimumLineHeight = lineHeight

let attributes: [NSAttributedString.Key: Any] = [
.paragraphStyle: style,
.baselineOffset: (lineHeight - font.lineHeight) * 0.26
]

let attrString = NSAttributedString(string: text,
attributes: attributes)
self.attributedText = attrString
self.textAlignment = .center
self.numberOfLines = 2
}
}
}
8 changes: 7 additions & 1 deletion HMH_iOS/HMH_iOS/Global/Extension/UIStackView+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
// Created by 지희의 MAC on 12/29/23.
//

import Foundation
import UIKit

extension UIStackView {
func addArrangeSubViews(_ views: [UIView]) {
views.forEach { self.addArrangedSubview($0) }
}
}
19 changes: 19 additions & 0 deletions HMH_iOS/HMH_iOS/Global/Extension/UIView+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@
import UIKit

extension UIView {

func addSubviews(_ views: UIView...) {
views.forEach { self.addSubview($0) }
}

func makeShadow (radius : CGFloat, offset : CGSize, opacity : Float){
layer.shadowColor = UIColor.darkGray.cgColor
layer.shadowOffset = offset
layer.shadowRadius = radius
layer.shadowOpacity = opacity
layer.masksToBounds = false
}

func makeCornerRound (radius : CGFloat) {
layer.cornerRadius = radius
layer.masksToBounds = true
}

func makeBorder (width : CGFloat ,color : UIColor ) {
layer.borderWidth = width
layer.borderColor = color.cgColor
}
}

0 comments on commit 1deb723

Please sign in to comment.