快速連結

2023年9月19日

[Swift5]只想要UIView某一邊使用圓弧


 let cornerPath = UIBezierPath(roundedRect: myView.bounds, byRoundingCorners: [.bottomLeft, .topLeft], cornerRadii:  CGSize(width: 8, height:  8))
 let maskLayer = CAShapeLayer()
 maskLayer.path = cornerPath.cgPath
 myView.layer.mask = maskLayer
UIBezierPath參數內容:
roundedRect:要做mask的UIView的bounds。
byRoundingCorners:要做圓弧角的地方,有左上、左下、右上、右下,也有全部都要的allCorners可以用。
cornerRadii:圓角大小,CGSize物件,寬度=水平弧度,高度=垂直弧度。詳細可以看這篇:Why is cornerRadii parameter of CGSize type in...

2023年6月13日

[Vue3][筆記]vue-i18n 讀取public資料夾內json file

最近做一個委託,對方需要網站有多國語系,並且他能夠自己去更新語言包內的文字而不需要透過我們再編譯。
vue-i18n可以滿足我們製作多國語系的功能,可惜網路上很少有在討論vue3+i18n+public資料讀取的資訊。
基於vue專案的設計,public資料夾是不能直接上方宣告import js、json檔案來利用的,必須透過await import/await fetch來讀取進來。(如果有搞錯請留言跟我說QQ)
這就導致了通用的vue-i18n範例是不能使用的。 以下是我搜尋後找到的方法,從vue2改寫而來! 參考的文章:VueJS 2.0 教學筆記: i18n 多語套件進階篇

2023年5月4日

【筆記】動態讀取cell

先獨立建立一個User interface:Empty,命名為MyInfoCell。
一開始看到會是空白一片,我們加入一個TableViewCell。
=>

接著建立Swift File,名字為InfoCell,Class名稱也是 InfoCell:

class InfoCell : UITableViewCell{
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var detailLabel: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        selectionStyle = .none
    }
}
將MyInfoCell內的TableViewCell的Custom Class指向InfoCell。

最後,在主要的class內加入delegate,然後加入這幾行:

override func viewDidLoad() {
        let myNib = UINib(nibName: "MyInfoCell", bundle: nil)
        tableview.register(myNib, forCellReuseIdentifier: "myCell")
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableview.dequeueReusableCell(withIdentifier: "addressCell") as! InfoCell
}

2023年3月26日

2023年2月12日

Timer.scheduledTimer沒有執行

狀況:在接取API responce回來後,呼叫了Timer.scheduledTimer,但Timer.scheduledTimer似乎沒有跑⋯⋯這是為什麼呢? 原因:因為主要是沒有在main queue上執行喔~ 改之前:

func startTimer(){
        if self.timer == nil{
            timer = Timer.scheduledTimer(timeInterval: REFRESH_DURATION_SEC, target: self, selector: #selector(endTimer), userInfo: nil, repeats: false)
        }
    }
改之後: