@IBAction func transferData(_ sender: Any) {
//(identifier: "Next viewcontroller의 storyboard ID")
guard let receiveController = self.storyboard?.instantiateViewController(identifier: "secondViewController") as? SecondViewController else { return }
receiveController.name = nameTextfield.text
receiveController.email = emailTextfield.text
receiveController.isOnoff = sampleSwitch.isOn
receiveController.frequency = sampleSlider.value
//코드로 뷰간의 present연결 (이때,스토리보드에선 뷰간 연결해주면 안됨)
self.present(receiveController, animated: true, completion: nil)
}
//이전 viewcontroller에서 넘겨준 데이터를 어떤 형식으로 받을지 선언
//내부에선 아울렛 변수를 참조할 수 없어 만들어줌
var name: String?
var email: String?
var isOnoff: Bool?
var frequency: Float?
//뒤로가기 Action(이때도 스토리보드에선 뷰간 연결해주면 안됨)
@IBAction func backScreen(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
//navigation stack에서 RootViewController(처음 뷰)를 제외한 쌓여있는 모든 뷰를 제거하여 최상위 뷰로 되게 해줌.
self.present(lvc, animated: true, completion: {
self.navigationController?.popToRootViewController(animated: true)
})
import UIKit
class CustomButton: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
//값이 커질수록 둥글
self.layer.cornerRadius = 0.02 * self.bounds.size.width
//버튼 배경색
self.backgroundColor = UIColor(red: 8/255, green: 37/255, blue: 108/255, alpha: 1)
//버튼의 textcolor
self.tintColor = UIColor.white
//버튼 text 굵기 및 크기
self.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20)
//버튼의 외곽선컬러
//self.layer.borderColor =
//버튼의 외곽선두께: 값이 커질수록 두꺼움
//self.layer.borderWidth =
}
}
동일한 Action을 하는 button이 여러 개일 때, 한 button의 Action을 우선 선언한 후 그 Action func의 블랙포인트('Line 26')에서 나머지 button으로 드래그해주면 된다.
self.navigationController?.navigationBar.barTintColor = .white
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.tintColor = UIColor(red: 7/255, green: 59/255, blue: 163/255, alpha: 1.0)
self.navigationController?.navigationBar.topItem?.title = ""
//tableview cell 간 구분선 없애기
Tableview.separatorStyle = UITableViewCell.SeparatorStyle.none
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView()
//몇번째 section의 header를 custom 할 것인지 정하기
if section == 2 {
let friendCountLabel = UILabel()
friendCountLabel.text = "친구 \(self.friendInformations.count)"
friendCountLabel.textColor = UIColor(red: 129/255, green: 129/255, blue: 129/255, alpha: 1.0)
friendCountLabel.frame = CGRect.init(x: 16, y: 8, width: 35, height: 17)
friendCountLabel.font = UIFont.systemFont(ofSize: 11)
headerView.addSubview(friendCountLabel)
}
return headerView
}
//custom한 cell의 header를 제외한 다른 cell header (header height = 0으로 하여) 없애주기
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 0 {
return 0
}
else if section == 1 {
return 0
}
else if section == 2 {
return 35
}
return tableView.sectionHeaderHeight
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
if indexPath.section == 2 {
let deleteAction = UIContextualAction(style: .destructive, title: "삭제", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
success(true)
self.friendInformations.remove(at: indexPath.row)
self.friendTableview.reloadData()
})
return UISwipeActionsConfiguration(actions: [deleteAction])
}
else {
return UISwipeActionsConfiguration()
}
}
@IBAction func settingBtnAction(_ sender: Any) {
let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let manageAction = UIAlertAction(title: "친구 관리", style: .default)
let settingAction = UIAlertAction(title: "전체 설정", style: .default)
let cancelAction = UIAlertAction(title: "취소", style: .cancel)
optionMenu.addAction(manageAction)
optionMenu.addAction(settingAction)
optionMenu.addAction(cancelAction)
self.present(optionMenu, animated: true, completion: nil)
}