iOS Swift圆形视图内的单元格显示不正确

时间:2018-02-24 10:26:53

标签: ios swift rounding uicollectionviewcell

晚上,我有一个日历集。 单元格在第一次显示不正确的圆形视图,但重新加载后,它们会正确显示。

我知道问题在于,细胞第一次不知道框架的正确尺寸。

我尝试过的事情:

1-在layoutSubviews()内调用圆函数:只有右侧正确舍入

2 - 调用cellWillLayout内的圆函数:无变化

这是舍入函数:

func makeRound() {
        print("rounding")
        currentDayView.layer.cornerRadius = currentDayView.frame.height/2
        currentDayView.layer.masksToBounds = true
        currentDayView.clipsToBounds = true

        selectedDayView.layer.cornerRadius = selectedDayView.frame.height/2
        selectedDayView.layer.masksToBounds = true
        selectedDayView.clipsToBounds = true
    }

enter image description here enter image description here

有什么建议吗?

2 个答案:

答案 0 :(得分:1)

进行圆角舍入的最佳位置是在每个视图的layoutSubviews中或(例如,如果您尚未对其进行细分)将其放入视图控制器viewDidLayoutSubviews中。

您的案例中的每个观点都是layoutSubviewscurrentDayView的{​​{1}}。

答案 1 :(得分:0)

您需要覆盖override func layoutSubviews() { super.layoutSubviews() self.makeRound() } 方法,然后在其中调用您的方法:

p3= re.compile(r"\w+(wo)?man")
t='what if catwoman and superman got married!'
r3=p3.search(t)
print(r3.group())