如何在swift中使用DLRadiobutton显示默认选中的单选按钮

时间:2018-03-15 17:17:39

标签: ios swift radio-button dlradiobutton

当应用程序加载时我必须选择选项但我想显示应用程序加载时选择的默认单选按钮.. 我已经使用此代码显示单选按钮

public func createRadioButton(frame : CGRect, title : String, color : UIColor) -> DLRadioButton {
     radioButton = DLRadioButton(frame: frame);
    radioButton.titleLabel!.font = UIFont.systemFont(ofSize: 14);
    radioButton.setTitle(title, for: []);
    radioButton.setTitleColor(color, for: []);
    radioButton.iconColor = color;
    radioButton.indicatorColor = color;
    radioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignment.left;
    radioButton.addTarget(self, action: #selector(ViewController.logSelectedButton), for: UIControlEvents.touchUpInside);
    self.view.addSubview(radioButton);

    return radioButton;
}

@objc @IBAction public func logSelectedBtn(radioButton : DLRadioButton) {


    if (radioButton.isMultipleSelectionEnabled) {
        for button in radioButton.selectedButtons() {
            print(String(format: "%@ is selected.\n", button.titleLabel!.text!));

        }
    } else {

        hello2 = radioButton.selected()!.titleLabel!.text!
        print(String(format: "%@ is selected.\n", hello2));
    }
}

2 个答案:

答案 0 :(得分:0)

使用此代码:

require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';



{
    private $_filters = array();

    public function addFilter(Zend_Search_Lucene_Analysis_TokenFilter $filter)
    {
        $this->_filters[] = $filter;
    }

    /**
     * Apply filters to the token. Can return null when the token was removed.
     *
     * @param Zend_Search_Lucene_Analysis_Token $token
     * @return Zend_Search_Lucene_Analysis_Token
     */
    public function normalize(Zend_Search_Lucene_Analysis_Token $token)
    {
        foreach ($this->_filters as $filter) {
            $token = $filter->normalize($token);

            // resulting token can be null if the filter removes it
            if ($token === null) {
                return null;
            }
        }

        return $token;
    }
}

答案 1 :(得分:0)

更改属性检查器对我不起作用,因此我以编程方式将其添加如下:

在ViewDidLoad方法中:

self.yourRadioButton.isSelected = true

你去了!

enter image description here