UITableView-কে রাউন্ডেড কর্নার দিন
টেবল ভিউ iOS-এ সবচেয়ে মৌলিক UI কম্পোনেন্ট। এটিকে রাউন্ডেড কর্নার দেওয়া খুব সহজ—শুধু লেয়ারের cornerRadius সেট করলেই হয়।
স্টোরিবোর্ড সেটআপ
- Single View App তৈরি করুন।
Main.storyboard-এUITableViewযোগ করুন।- প্রোটোটাইপ সেল যোগ করে রিইউজ আইডেন্টিফায়ার
"cell"দিন। - কাস্টম
UITableViewCellসাবক্লাস তৈরি করুন (ঐচ্ছিক)।
ViewController কোড
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
// রাউন্ডেড কর্নার
tableView.layer.cornerRadius = 10
tableView.layer.masksToBounds = true // কনটেন্ট ক্লিপ করতে
tableView.backgroundColor = .cyan
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "Row \(indexPath.row)"
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
}
টিপস: masksToBounds = true না দিলে সেলের কনটেন্ট কর্নারের বাইরে চলে যাবে।