์ ํธ์ ์ด์ด์ ์ฑํ ๋ฐฉ UI๋ฅผ ๊ตฌํํด๋ณด๊ฒ ๋ค.
์ฑํ ๋ฐฉ์ ํด๋ฝํ์ฐ์ค ์ฑ์ UI๋ฅผ ์ฐธ๊ณ ํ์ฌ ๋ง๋ค์๋ค.
๊ฒฐ๊ณผ๋ฌผ ํ๋ฉด
์ฑํ ๋ฐฉ ์์ธ ํ๋ฉด ๊ตฌํ
์ฑํ ๋ฐฉ์๋ ๊ฐ ์ ์ ๋ณ ํ๋กํ ์ฌ์ง์ด ๋ค์ด๊ฐ์ผ ํ๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ํ๋กํ ํ๋ฉด๋ ๊ตฌํํด๋ณด์
ํ๋กํ ํ๋ฉด ๊ตฌํ
ํ๋กํ ํ๋ฉด์ ํ๋กํ ์ฌ์ง์ ์ถํ Amazon S3 ๋ฅผ ํ์ฉํด ๊ด๋ฆฌํ ์์ ์ด๋ค. (REST API๋ก ๊ด๋ จ URL ์ ๋ฐ์ ์์ ). ๊ทธ๋์ ์ด๋ฏธ์ง URL ๋ก ํ๋กํ ์ฌ์ง์ ๋ณด์ฌ์ค ์ ์๋ UI ๊ฐ ๋ณ๋๋ก ํ์ํ๋ค.
Swift ์์๋ AsyncImage๋ฅผ ์ฌ์ฉํด์ ์ด๋ฏธ์ง์ url๋ก(html ์์ image ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ์ ์ฌ) ์ฌ์ง์ ๋ณด์ฌ์ค ์ ์๋ค. ์๋ ์ฝ๋๋ฅผ ๊ตฌํํ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
import SwiftUI
struct ProfileItem: View {
var talkRoomTitle: String
var imageUrl: String
var body: some View {
VStack(alignment: .leading){
Circle() // Circle element ์์ image๋ฅผ ์ค๋ฒ๋ ์ดํ์ฌ ํ๋กํ ์ฌ์ง์ ๋ง๋ฌ
.overlay(
AsyncImage(
url: URL(string: imageUrl),
content: { image in
image.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 100, height: 100)
.clipShape(Circle())
},
placeholder: {
ProgressView()
}
)
)
.frame(width: 100, height: 100)
Text(talkRoomTitle) // ์ฑํ
๋ฐฉ์ ๋ค์ด๊ฐ๋ ์ฌ์ฉ์์ ์ด๋ฆ
.frame(width: 100)
.lineLimit(2)
.font(.subheadline)
}
}
}
struct ProfileItem_Previews: PreviewProvider {
static var previews: some View {
ProfileItem(
talkRoomTitle: "John",
imageUrl: "<https://cdn.pixabay.com/photo/2015/03/03/18/58/woman-657753_960_720.jpg>"
)
}
}
์ฑํ ๋ฐฉ ์์ธํ๋ฉด(With ์ ์ )
๊ฐ ์ฑํ ๋ฐฉ์ ์ ์ ๊ฐ ๋ค์ด์จ ํ๋ฉด์ ๊ตฌํํด๋ณด์.
import SwiftUI
struct TalkRoomDetail: View {
@Environment(\\.presentationMode) var presentationMode
var roomTitle: String
var mbtiType: Array<String>
let userList = ModelData().userInfos
let columns = [
GridItem(.adaptive(minimum: 100))
]
var body: some View {
ZStack(alignment: .leading){
Color.white.ignoresSafeArea()
.navigationBarBackButtonHidden(true)
.navigationBarHidden(true)
VStack(alignment: .leading){
Button(action: {
self.showingAlert = true
}){
Text("๋๊ฐ๊ธฐ")
}.alert(isPresented: $showingAlert){
Alert(title: Text("์ฑํ
๋ฐฉ ๋๊ฐ๊ธฐ"), message: Text("์ฑํ
๋ฐฉ์ ๋๊ฐ์๊ฒ ์ต๋๊น?"),
primaryButton: .destructive(Text("๋๊ฐ๊ธฐ"), action: {
presentationMode.wrappedValue.dismiss()
})
, secondaryButton: .cancel(Text("์ทจ์")))
}
.padding()
Text(roomTitle)
.font(.title)
.bold()
.padding(.leading)
.padding(.top)
Text(mbtiType.joined(separator: " "))
.font(.headline)
.bold()
.padding(.leading)
Divider()
ScrollView{
LazyVGrid(columns: columns, spacing: 10) {
ForEach(userList, id:\\.self) {i in
ProfileItem(talkRoomTitle: i.userId, imageUrl: i.profilePic)}
}
}.frame(width: .infinity, height: 400)
Divider()
}
}
}
}
struct TalkRoomDetail_Previews: PreviewProvider {
static var previews: some View {
TalkRoomDetail(
roomTitle: "์ ์ฃผ๋ ์ฌํ์ฐ",
mbtiType: ["#ISTJ","#ENFP"]
)
}
}
์ฑํ ๋ฐฉ UI๋ก ์ ๊ทผํ๊ธฐ ์ํด ์ด์ UI์์๋ NavigationView๋ฅผ ์ด์ฉํ์ฌ ์ ๊ทผํ๋ค. NavigationView๋ฅผ ์ด์ฉํด ์ ๊ทผํ๋ฉด ๋ค๋ก ๋์๊ฐ๋ ํ๋ฉด(Navigation UI)์ด ์๋์ผ๋ก ์์ฑ๋๋ค. ๊ทธ๋์ ์ฝ๋ ๋ด
@Environment(\\.presentationMode) **var** presentationMode ๋ฅผ ์ด์ฉํด NavigationView๋ก ์ ๊ทผํ View ์์ ๋ค๋ก๊ฐ๊ธฐ ๋ฒํผ์ด ์๋๋ก ๊ฐ๋ฐํ๋ค.
๋ํ ์ฑํ ๋ฐฉ์ ์ ์ ๋ ํจ์์ ํ๋ผ๋ฏธํฐ๋ก ๋ฐ๋ ๊ฒ์ด ์๋ ๋ณ๋ ๋ณ์๋ก ๋ฐ์ ์ฒ๋ฆฌํ๋๋ก ํ์๋ค. (REST API ๋๋ NoSQL(Firebase or Mongo DB)์์ ๋ฐ์์ค๋๋ก)
Grid View ๊ตฌํ
์ ์ ๋ณ ํ๋กํ์ Grid View๋ฅผ ์ด์ฉํด 3 * N ๊ฐ์ ์ ์ ๊ฐ ๋ณด์ฌ์ง ์ ์๋๋ก UI๋ฅผ ๊ตฌ์ฑํ์๋ค.
์ฌ๊ธฐ์ ์ฌ์ฉํ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค.
LazyVGrid(columns: columns, spacing: 10) {
ForEach(userList, id:\\.self) {i in
ProfileItem(talkRoomTitle: i.userId, imageUrl: i.profilePic)}
}
์ฑํ ๋ฐฉ ๋๊ฐ๊ธฐ ํ๋ฉด ๊ตฌํ
Navigation ๊ธฐ๋ฅ์์ ๋ค๋ก๊ฐ๊ธฐ ๋ฒํผ์ Hidden ์์ผฐ๊ธฐ ๋๋ฌธ์ ๋ณ๋์ ๋๊ฐ๊ธฐ ๋ฒํผ์ ๋ง๋ค์๋ค.
Button(action: {
self.showingAlert = true
}){
Text("๋๊ฐ๊ธฐ")
}.alert(isPresented: $showingAlert){
Alert(title: Text("์ฑํ
๋ฐฉ ๋๊ฐ๊ธฐ"), message: Text("์ฑํ
๋ฐฉ์ ๋๊ฐ์๊ฒ ์ต๋๊น?"),
primaryButton: .destructive(Text("๋๊ฐ๊ธฐ"), action: {
presentationMode.wrappedValue.dismiss()
})
, secondaryButton: .cancel(Text("์ทจ์")))
}
.padding()
๋ค์์๋ ํค์๋ ๊ฒ์์ ๊ตฌํํ๊ณ (REST API ์ ์ฐ๊ฒฐ) ๊ฒ์ ํ๋ฉด์ ๊ตฌํํด๋ณด์.
'IOS(Swift)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[IOS/Swift] MBTI ์นด๋ ์ ํ ๊ฒ์ UI ๊ตฌํ (0) | 2022.05.22 |
---|---|
[IOS/Swift] ์ฝํ ์ธ ๊ฒ์ ์ฑ ๊ตฌํ - 4. ๋ก๊ทธ์ธ UI ๊ตฌํ (0) | 2022.04.04 |
[IOS/Swift] ์ฝํ ์ธ ๊ฒ์ ์ฑ ๊ตฌํ - 3. ํ์๊ฐ์ UI ๊ตฌํ (0) | 2022.04.04 |
[IOS/Swift] ์ฝํ ์ธ ๊ฒ์ ์ฑ ๊ตฌํ - 1. ์ฝํ ์ธ UI ๊ตฌํ (0) | 2022.03.05 |