从 ScrollView Swift 中删除子视图

Remove subviews from ScrollView Swift(从 ScrollView Swift 中删除子视图)
本文介绍了从 ScrollView Swift 中删除子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 for 循环在我的滚动视图中创建标签和按钮.是否可以删除我的滚动视图内的所有对象?(我想用新内容更新它)

I use a for-loop to create labels and buttons inside my scrollView. Is it possible to remove all objects indside my scrollView? (I would like to update it with new content)

for peop in personArray{

        scrollView.clearContent ??????


        // Name label
        var label: UILabel = UILabel()
        label.frame = CGRectMake(8, CGFloat(nameHeight), 183, 21)
        label.backgroundColor = UIColor.whiteColor()
        label.textColor =  UIColor(red: 90/255.0, green: 187/255.0, blue: 206/255.0, alpha: 1.0)
        label.textAlignment = NSTextAlignment.Left
        label.font = UIFont (name: "HelveticaNeue-Light", size: 14)
        label.text = " (peop.getName()) - (sex)"
        self.scrollView.addSubview(label)


        //Delete button
        var button = UIButton.buttonWithType(UIButtonType.System) as UIButton
        button.tag = playerId
        button.frame = CGRectMake(199, CGFloat(nameHeight), 37, 21)
        button.backgroundColor = colorWheel.colorsArray[7]
        button.setTitle("Slet", forState: UIControlState.Normal)
        button.addTarget(self, action: "delAction:", forControlEvents: UIControlEvents.TouchUpInside)
        button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        self.scrollView.addSubview(button)
        button.titleLabel!.font = UIFont(name: "HelveticaNeue-Light", size: 14)


        scrollHeight = scrollHeight + 29
        nameHeight = nameHeight + 29
        playerId++
    }
    scrollView.contentSize = CGSize(width: 20.0, height: CGFloat(nameHeight))
}

func delAction(sender: UIButton!){
    personArray.removeAtIndex(sender.tag)
    updatePeople()
}

推荐答案

你试过了吗?

let subViews = self.scrollView.subviews
for subview in subViews{
    subview.removeFromSuperview()
}

这篇关于从 ScrollView Swift 中删除子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)