본문 바로가기

전체 글

(160)
ios] 코드로 UIImage, UIlabel, UIbutton 화면에 그리기UICollectionViewCell anchor를 각 각 설정하면 코드가 길어지기 때문에 아래처럼 extension을 이용해서 미리 선언을 해준다. extension UIView { func anchor(top: NSLayoutYAxisAnchor? = nil, left: NSLayoutXAxisAnchor? = nil, bottom: NSLayoutYAxisAnchor? = nil, right: NSLayoutXAxisAnchor? = nil, paddingTop: CGFloat = 0, paddingLeft: CGFloat = 0, paddingBottom: CGFloat = 0, paddingRight: CGFloat = 0, width: CGFloat? = nil, height: CGFloat? = nil) { translatesA..
ios] 코드로 UICollectionViewCell 설정하고 UICollectionViewController에서 적용하기 -View - FeedCell.swift import UIKit class FeedCell: UICollectionViewCell{ //MARK: - Propertie //MARK: - Lifecycle override init(frame: CGRect){ super.init(frame: frame) backgroundColor = .brown } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } //MARK: - API //MARK: - Actions //MARK: - Helpers } -Controller - FeedController class FeedController: UICollection..
ios] 코드로 UITabBarController의 탭에 UICollectionViewController를 선언하고 콜렉션뷰 설정하기(테이블뷰처럼) class FeedController: UICollectionViewController- UITabBarController에 선언되어있는 FeedController은 UICollectionViewController이다 이 상태로 런을 하면 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'같은 에러가 나타난다 UICollectionView는 Nil이 아닌 레이아웃 매개 변수로 초기화해야 하기때문. let layout = UICollectionViewFlowLayout() let feed = templateNavigationController(unselectedIm..
ios] 코드로 UITabBarController 만들고 탭 별 뷰컨트롤러 네비게이션 컨트롤러로 만들고 tabBarItem 수정하기 우선 각 각의 컨트롤러는 import UIKit class SearchController: UIViewController{ override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .yellow } } 이런식으로 백그라운드 색상만 설정은 해놨다. 그리고 UITabBarController을 상속받은 MainTabController에서 templateNavigationController함수를 만들어 각 각의 뷰컨트롤러를 네비게이션컨트롤러로 선언을 해주고 unselectedImage와 selectedImage를 설정을 해줬다. func configureViewControllers(){ view.backgroundColor = .white..
swift] attributedText으로 텍스트마다 다양한 스타일(폰트,사이즈,색상), NSMutableParagraphStyle으로 텍스트사이 간격주기 messageTextView.attributedText = attributedText 위 사진처럼 messageTextView에 attributedText을 통해 총 3가지의 폰트를 설정해줬습니다. let attributedText = NSMutableAttributedString(string: tweet.user.name, attributes: [NSAttributedString.Key.font:UIFont.boldSystemFont(ofSize: 16)]) let usernameString = " \(tweet.user.username)\n" attributedText.append(NSAttributedString(string: usernameString, attributes: [NSAttribute..
switf] collectionview 셀 간격 설정하기 developer.apple.com/documentation/uikit/uicollectionviewdelegateflowlayout/1617705-collectionview Apple Developer Documentation developer.apple.com func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 0 } minimumLineSpacingForSectionAt을 사용해서 셀간격을 조절한다. (섹션의 연속적인 행 또는 열 사이의 간격을..
ios] 네비게이션바 이미지, 버튼 설정 가운데 로고 적용하기 (navigationItem.titleView), 네비게이션바 배경색 설정하기 private func setupRemainingNavItems() { let titleImageView = UIImageView(image: imageLiteral(resourceName: "title_icon")) titleImageView.frame = CGRect(x: 0, y: 0, width: 34, height: 34) titleImageView.contentMode = .scaleAspectFit navigationItem.titleView = titleImageView navigationController?.navigationBar.backgroundColor = .white navigat..
ios] UIButton 코드로 설정하기 (버튼안에 이미지, 타이틀 이동 시키기) let followButton: UIButton = { let button = UIButton() button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14) button.setImage(UIImage(systemName: "person.fill.badge.plus"), for: .normal) button.tintColor = twitterBlue button.layer.cornerRadius = 5 button.layer.borderColor = twitterBlue.cgColor button.layer.borderWidth = 1 button.setTitle("Follow", for: .normal) button.setTitleColor(twitterB..