Skip to content

Commit

Permalink
#3 add FreeBoard TableView
Browse files Browse the repository at this point in the history
  • Loading branch information
JunseokNoh committed Jul 21, 2021
1 parent 9bd3d7a commit d3396a2
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 38 deletions.
1 change: 1 addition & 0 deletions KNU_CSE/KNU_CSE/Custom/Cell/BoardTitleCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ extension BoardTitleCell{
func setTitle(title: String) {
titleLabel.text = title
titleLabel.textAlignment = .center
titleLabel.font = UIFont.systemFont(ofSize: 15, weight: .semibold)
}
}
151 changes: 134 additions & 17 deletions KNU_CSE/KNU_CSE/Custom/Cell/FreeBoardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,72 @@ import SnapKit

class FreeBoardCell : UITableViewCell {
static let identifier = "FreeBoardCell"
var titleLabel = UILabel()

var height:CGFloat!{
didSet{
setUpConstraints()
}
}

var authorLabel:UILabel!{
didSet{
authorLabel.textAlignment = .left
authorLabel.textColor = UIColor.black
authorLabel.font = UIFont.systemFont(ofSize: 13, weight: .light)
}
}

var dateLabel:UILabel!{
didSet{
dateLabel.textAlignment = .right
dateLabel.textColor = UIColor.black
dateLabel.font = UIFont.systemFont(ofSize: 12, weight: .light)
}
}

var titleLabel:UILabel!{
didSet{
titleLabel.textAlignment = .left
titleLabel.textColor = UIColor.black
titleLabel.font = UIFont.systemFont(ofSize: 17, weight: .bold)
}
}

var contentLabel:UILabel!{
didSet{
contentLabel.textAlignment = .left
contentLabel.textColor = UIColor.black
contentLabel.font = UIFont.systemFont(ofSize: 15, weight: .regular)
contentLabel.numberOfLines = 2
}
}

var commentImage:UIImageView!{
didSet{
let image = UIImage(systemName: "text.bubble.fill")
commentImage.image = image
commentImage.tintColor = .lightGray
}
}

var commentLabel:UILabel!{
didSet{
commentLabel.textAlignment = .left
commentLabel.textColor = UIColor.black
commentLabel.font = UIFont.systemFont(ofSize: 13, weight: .regular)
}
}

var action :()->() = {}
var cellBtn = UIButton()

var board : FreeBoard!{
var viewModel : Board!{
didSet{
let title = "\(board.building)-\(board.roomNum)호(\(board.currentSeat)/\(board.totalSeat))"
self.setTitle(title: title)
self.setAuthorText(title: viewModel.author)
self.setDateText(title: viewModel.date)
self.setTitleText(title: viewModel.title)
self.setContentText(title: viewModel.content)
self.setCommentText(title: String(viewModel.numberOfcomment))
}
}

Expand All @@ -29,47 +87,106 @@ class FreeBoardCell : UITableViewCell {
self.action()
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.initUI()
self.addView()
self.setUpConstraints()
//self.setUpConstraints()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func initUI(){

authorLabel = UILabel()
dateLabel = UILabel()
titleLabel = UILabel()
contentLabel = UILabel()
commentImage = UIImageView()
commentLabel = UILabel()
}

func addView(){
self.contentView.addSubview(cellBtn)
self.cellBtn.addSubview(authorLabel)
self.cellBtn.addSubview(dateLabel)
self.cellBtn.addSubview(titleLabel)
//self.contentView.addSubview(titleLabel)
self.cellBtn.addSubview(contentLabel)
self.cellBtn.addSubview(commentImage)
self.cellBtn.addSubview(commentLabel)
}

func setUpConstraints(){

self.cellBtn.snp.makeConstraints{ make in
make.width.equalToSuperview()
make.height.equalToSuperview()
}

self.authorLabel.snp.makeConstraints{ make in
make.top.equalToSuperview().offset(10)
make.left.equalToSuperview().offset(20)
make.width.equalToSuperview().multipliedBy(0.5)
make.height.equalTo(height*0.2)
}

cellBtn.snp.makeConstraints{ make in
make.left.right.top.bottom.equalToSuperview()
self.dateLabel.snp.makeConstraints{ make in
make.top.equalTo(authorLabel.snp.top)
make.left.equalTo(self.authorLabel.snp.right)
make.right.equalToSuperview().offset(-20)
make.height.equalTo(height*0.2)
}

titleLabel.snp.makeConstraints{ make in
make.left.right.top.bottom.equalToSuperview()
self.titleLabel.snp.makeConstraints{ make in
make.top.equalTo(authorLabel.snp.bottom).offset(0)
make.left.equalToSuperview().offset(20)
make.right.equalToSuperview().offset(-20)
make.height.equalTo(height*0.2)
}

self.contentLabel.snp.makeConstraints{ make in
make.top.equalTo(titleLabel.snp.bottom).offset(0)
make.left.equalToSuperview().offset(20)
make.right.equalToSuperview().offset(-20)
make.height.equalTo(height*0.25)
}

self.commentLabel.snp.makeConstraints{ make in
make.top.equalTo(self.contentLabel.snp.bottom).offset(0)
make.right.equalToSuperview().offset(-20)
make.height.equalTo(height*0.15)
make.width.equalTo(height*0.15)
}

self.commentImage.snp.makeConstraints{ make in
make.top.equalTo(self.contentLabel.snp.bottom).offset(0)
make.right.equalTo(commentLabel.snp.left).offset(-5)
make.height.equalTo(height*0.15)
make.width.equalTo(height*0.15)
}

}
}

extension FreeBoardCell{
func setTitle(title: String) {
func setAuthorText(title: String) {
authorLabel.text = title
}

func setDateText(title: String) {
dateLabel.text = title
}

func setTitleText(title: String) {
titleLabel.text = title
titleLabel.textAlignment = .center
}

func setContentText(title: String) {
contentLabel.text = title
}

func setCommentText(title: String) {
commentLabel.text = title
}
}
28 changes: 16 additions & 12 deletions KNU_CSE/KNU_CSE/Main Tab/Board/FreeBoard/FreeBoardModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@

import Foundation

class FreeBoard:BaseObject{
var roomId : Int
var roomNum : Int
var building : String
var totalSeat : Int
var currentSeat : Int
class Board:BaseObject{
var boardId : Int
var category : Int
var title : String
var content : String
var author : String
var date : String
var numberOfcomment:Int

init(roomId:Int, roomNum:Int, building:String, totalSeat:Int, currentSeat:Int) {
self.roomId = roomId
self.roomNum = roomNum
self.building = building
self.totalSeat = totalSeat
self.currentSeat = currentSeat
init(boardId:Int, category:Int, title:String, content:String, author:String, date:String, numberOfcomment:Int) {
self.boardId = boardId
self.category = category
self.title = title
self.content = content
self.author = author
self.date = date
self.numberOfcomment = numberOfcomment
super.init()
}

Expand Down
9 changes: 5 additions & 4 deletions KNU_CSE/KNU_CSE/Main Tab/Board/FreeBoard/FreeBoardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class FreeBoardView : UIViewController{

var freeboardTableView :UITableView!{
didSet{
freeboardTableView.translatesAutoresizingMaskIntoConstraints = false
freeboardTableView.register(FreeBoardCell.self, forCellReuseIdentifier: FreeBoardCell.identifier)
freeboardTableView.dataSource = self
freeboardTableView.rowHeight = cellRowHeight * 0.1
freeboardTableView.rowHeight = cellRowHeight * 0.115
freeboardTableView.tableFooterView = UIView(frame: .zero)
freeboardTableView.separatorInset.left = 0
}
}

Expand Down Expand Up @@ -49,7 +49,7 @@ class FreeBoardView : UIViewController{
make.left.equalToSuperview()
make.right.equalToSuperview()
make.top.equalTo(self.view.safeAreaLayoutGuide)
make.bottom.equalToSuperview()
make.bottom.equalTo(self.view.safeAreaLayoutGuide)
}
}
}
Expand All @@ -63,7 +63,8 @@ extension FreeBoardView : UITableViewDataSource{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: FreeBoardCell.identifier, for: indexPath) as! FreeBoardCell
cell.selectionStyle = .none
cell.board = freeBordViewModel.boards[indexPath.row]
cell.viewModel = freeBordViewModel.boards[indexPath.row]
cell.height = cellRowHeight * 0.115
cell.cellBtn.addAction {
print("\(indexPath.row)")
}
Expand Down
22 changes: 17 additions & 5 deletions KNU_CSE/KNU_CSE/Main Tab/Board/FreeBoard/FreeBoardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@
import Foundation

struct FreeBoardViewModel{
var boards : [FreeBoard] = []
var boards : [Board] = []

init(){
self.setUpBoards()
}

mutating func setUpBoards(){
boards.append(FreeBoard(roomId: 101, roomNum: 101, building: "IT4", totalSeat: 30, currentSeat: 10))
boards.append(FreeBoard(roomId: 102, roomNum: 102, building: "IT4", totalSeat: 30, currentSeat: 11))
boards.append(FreeBoard(roomId: 103, roomNum: 103, building: "IT4", totalSeat: 30, currentSeat: 12))
boards.append(FreeBoard(roomId: 104, roomNum: 104, building: "IT4", totalSeat: 30, currentSeat: 13))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판1", content: "테스트 게시판1", author: "노준석", date: "2021 07.24 23:11",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판2", content: "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", author: "노준석", date: "2021 07.24 23:12",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판3", content: "테스트 게시판3", author: "노준석", date: "2021 07.24 23:13",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판4", content: "테스트 게시판4", author: "노준석", date: "2021 07.24 23:14",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판5", content: "테스트 게시판5", author: "노준석", date: "2021 07.24 23:15",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판6", content: "테스트 게시판6", author: "노준석", date: "2021 07.24 23:16",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
boards.append(Board(boardId: 1, category: 0, title: "테스트 게시판7", content: "테스트 게시판7", author: "노준석", date: "2021 07.24 23:17",numberOfcomment: 1))
}
}

0 comments on commit d3396a2

Please sign in to comment.