用于swift标签的Pagecontrol

时间:2017-05-27 12:27:38

标签: ios swift xcode8 uipageviewcontroller uipagecontrol

我有视图控制器,它使用scrollview在标签中显示一些文本,但我想为该标签创建一个页面控件,这意味着带有页面控件的标签中的不同文本。我有以下代码用于标签。

导入基金会   导入UIKit

module linear_feedback_shift_reg( clk, reset, data_out );

// PARAMETERS //

parameter REGISTER_WIDTH = 2;   // width of initial and current states 
parameter INIT_STATE = 0;       // initialization state when reset process
parameter POLYNOMIAL = 3;       // 0x11 -- x^2 + x + 1
parameter RESET_ACTIVE = 1;     // reset process when reset port is RESET_ACTIVE
parameter CLK_ACTIVE = 1;       // clk process when clk port is CLK_ACTIVE

// PORTS //

input wire clk;
input wire reset;

output reg data_out;

// VARIABLES //

reg [REGISTER_WIDTH - 1 : 0] polynomial;
reg [REGISTER_WIDTH - 1 : 0] current_state;
reg next_bit;

integer i;

// BEHAVIORAL

always @* begin
    if(reset == RESET_ACTIVE) begin // reset process
        current_state = INIT_STATE;
        next_bit = 1'b0;
        data_out = 1'b0;
        polynomial = POLYNOMIAL;
    end 
    else begin  // clk process
        if(clk == CLK_ACTIVE) begin
            data_out = current_state[0];
            next_bit = current_state[REGISTER_WIDTH - 1];
            for( i = 0; i < REGISTER_WIDTH - 1; i = i + 1) begin
                if(polynomial[i] == 1'b1) begin
                    next_bit = next_bit ^ current_state[i];
                end
            end
            current_state = current_state >> 1;
            current_state[REGISTER_WIDTH - 1] = next_bit;
        end
    end
end 
endmodule

提前致谢。

1 个答案:

答案 0 :(得分:0)

为页面控制器和Scrollview创建IBOutlet

@IBOutlet weak var pageController: UIPageControl!
@IBOutlet weak var ScrollController: UIScrollView!

创建数组

 let pageString = ["showsHorizontalScrollIndicator working pagecontroller", "running christmas card contact in ", "from the application you can back the Address"]

为滚动视图创建委托方法 UIScrollViewDelegate和方法

class ViewController: UIViewController, UIScrollViewDelegate {}

功能和委托方法

// MARK:- Page Controller

func loadScrollView() {
    let pageCount : CGFloat = CGFloat(pageString.count)

    ScrollController.backgroundColor = UIColor.clear
    ScrollController.delegate = self
    ScrollController.isPagingEnabled = true
    ScrollController.contentSize = CGSize(width: ScrollController.frame.size.width * pageCount, height: ScrollController.frame.size.height)
    ScrollController.showsHorizontalScrollIndicator = false
    ScrollController.alwaysBounceVertical = false

    pageController.numberOfPages = Int(pageCount)
    pageController.addTarget(self, action: #selector(self.pageChanged), for: .valueChanged)

    for i in 0..<Int(pageCount) {
        print(self.ScrollController.frame.size.width)

        let textView = UILabel(frame: CGRect(x: self.ScrollController.frame.size.width * CGFloat(i), y: 0, width: ScreenWidth - 30 , height: 30))
        textView.text = pageString[i]
        textView.numberOfLines = 0
        textView.textColor = UIColor.white
        textView.textAlignment = .center
        self.ScrollController.addSubview(textView)
    }
}


//MARK: UIScrollView Delegate
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let viewWidth: CGFloat = scrollView.frame.size.width
    // content offset - tells by how much the scroll view has scrolled.
    let pageNumber = floor((scrollView.contentOffset.x - viewWidth / 50) / viewWidth) + 1
    pageController.currentPage = Int(pageNumber)
}


//MARK: Page tap action
@objc func pageChanged() {
    let pageNumber = pageController.currentPage
    var frame = ScrollController.frame
    frame.origin.x = frame.size.width * CGFloat(pageNumber)
    frame.origin.y = 0
    ScrollController.scrollRectToVisible(frame, animated: true)
}

最后在ViewDidload()

中调用函数
loadScrollView()