Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- node
- 알려줌
- 도메인
- TypeScript
- AWS
- Elastic Beanstalk
- 페이스북
- beanstalk
- nextjs
- fanzeel
- 카카오톡
- 웹뷰
- ios
- NeXT
- cors
- node.js
- swift
- 감사일기
- hybrid
- php
- react
- 안드로이드
- 네이티브
- angular
- https
- JavaScript
- Android
- angular4
- S3
- Route53
Archives
- Today
- Total
쪼렙 as! 풀스택
iOS - Storyboard 에서 UILabel 에 Padding 설정하기 본문
출처 : https://stackoverflow.com/a/33244365
스토리보드에서 바로 값을 설정할 수 있어서 매우 편리하다.
//
// PaddedLabel.swift
// TrainCentric
//
// Created by Arsonik
// https://stackoverflow.com/a/33244365/337934
//
import UIKit
@IBDesignable
class PaddedLabel: UILabel {
@IBInspectable var inset:CGSize = CGSize(width: 0, height: 0)
var padding: UIEdgeInsets {
var hasText:Bool = false
if let t = self.text?.count, t > 0 {
hasText = true
}
else if let t = attributedText?.length, t > 0 {
hasText = true
}
return hasText ? UIEdgeInsets(top: inset.height, left: inset.width, bottom: inset.height, right: inset.width) : UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
override func drawText(in rect: CGRect) {
super.drawText(in: rect.inset(by: padding))
}
override var intrinsicContentSize: CGSize {
let superContentSize = super.intrinsicContentSize
let p = padding
let width = superContentSize.width + p.left + p.right
let heigth = superContentSize.height + p.top + p.bottom
return CGSize(width: width, height: heigth)
}
override func sizeThatFits(_ size: CGSize) -> CGSize {
let superSizeThatFits = super.sizeThatFits(size)
let p = padding
let width = superSizeThatFits.width + p.left + p.right
let heigth = superSizeThatFits.height + p.top + p.bottom
return CGSize(width: width, height: heigth)
}
}
'개발 일지 > iOS & Android' 카테고리의 다른 글
Swift 5.4 - 키보드 올라올라올 때 애니메이션 정확히 동일한 curve 알기. (1) | 2021.06.01 |
---|---|
Android Webview 에서 javascript window 객체에 접근해, 네이티브 기능 실행하기 (0) | 2021.01.31 |
iOS - XIB 에서 가져온 TableViewCell의 Dynamic Height (self-sizing height) (0) | 2020.03.16 |
iOS 하이브리드앱, Javascript 로 웹뷰에 메세지 보내기 (네이티브 코드 사용할 수 있도록) (0) | 2019.12.28 |
iOS13 - 카카오 로그인, 페이스북 로그인등 application: openURL() 이 안불러질때;; (0) | 2019.12.05 |
Comments