{"id":341627,"date":"2022-11-23T21:00:10","date_gmt":"2022-11-23T21:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341627"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341627","title":{"rendered":"<span>\u041f\u0438\u0448\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 CustomStepper \u0432 Swift<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/github.com\/zontz\/CustomStepper\" rel=\"noopener noreferrer nofollow\">\u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/a><\/p>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c stepper, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0438\u0445 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e Apple \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430, \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c. \u042d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438  \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430 \u0434\u043b\u044f \u043a\u043e\u0444\u0435\u0439\u043d\u0438.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/138\/3eb\/261\/1383eb261d893ede84afba01cc3fd208.png\" width=\"818\" height=\"292\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/138\/3eb\/261\/1383eb261d893ede84afba01cc3fd208.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0441\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0432 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0438, \u043d\u043e \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0436\u0443 \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0442\u043a\u0443 \u043a\u043e\u0434\u043e\u043c, stackView \u0441 2 \u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438 (-,+) \u0438 \u043b\u0435\u0439\u0431\u043b.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0442\u0435\u043f\u043f\u0435\u0440, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 UIView. \u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 UI-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0442\u043e\u043c \u0432\u0437\u044f\u0442\u044c \u0432 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u044b.<\/p>\n<p>\u0421\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435  &#8212; \u043b\u043e\u0433\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043b\u0435\u0439\u0431\u043b\u0430.<\/p>\n<pre><code class=\"swift\">final class CustomStepper: UIView {      private lazy var currentValue = 1 }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c 2 \u043a\u043d\u043e\u043f\u043a\u0438 \u0438 \u043b\u0435\u0439\u0431\u043b,  \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u043d\u0430\u0448 \u0441\u0442\u0435\u043f\u043f\u0435\u0440. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c enum, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u043a\u043d\u043e\u043f\u043e\u043a. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u0435\u0433\u0438,  \u0434\u043b\u044f  \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c 2 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043e\u043a.<\/p>\n<pre><code class=\"swift\">    private enum ButtonState: Int, CaseIterable {         case decrease = 0         case increase     }      private lazy var decreaseButton: UIButton = {         let button = UIButton()         button.tag = ButtonState.decrease.rawValue         button.setTitleColor(.black, for: .normal)         button.setTitle(\"-\", for: .normal)         button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)         return button     }()              private lazy var currentStepValueLabel: UILabel = {         let label = UILabel()         label.textColor = .black         label.text = \"\\(currentValue)\"         label.font = .systemFont(ofSize: 15)         return label     }()              private lazy var increaseButton: UIButton = {         let button = UIButton()         button.tag = ButtonState.increase.rawValue         button.setTitle(\"+\", for: .normal)         button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)         button.setTitleColor(.black, for: .normal)         return button     }()<\/code><\/pre>\n<p>\u0418\u043c\u0435\u044f \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u043a \u043d\u0430\u0448\u0438\u043c \u043a\u043d\u043e\u043f\u043a\u0430\u043c.<\/p>\n<pre><code class=\"swift\">    \/\/MARK: - Actions     @objc private func buttonAction(_ sender: UIButton) {         let buttonState = ButtonState(rawValue: sender.tag)                  switch buttonState {         case .decrease:             currentValue = currentValue > 1 ? currentValue - 1 : currentValue         case .increase:             currentValue += 1         default:             return         }         currentStepValueLabel.text = \"\\(currentValue)\"     }<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430 \u0432 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"swift\">protocol CustomStepperOutput: AnyObject {     func customStepper(_ didChangeValue: Int) }  protocol CustomStepperInput: AnyObject {     func update(_ value:Int) }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a (\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438)<\/p>\n<pre><code class=\"swift\">\/\/MARK: - CustomStepperInput extension CustomStepper: CustomStepperInput {     func update(_ value: Int) {         currentValue = value     } }<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u0441\u0442\u0435\u043f\u043f\u0435\u0440. \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u043c \u043f\u043e\u0434 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u043c \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430, \u0433\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442  \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430. \u0421 \u044d\u0442\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443.<\/p>\n<pre><code class=\"swift\">import UIKit  final class MainVC: UIViewController {      private lazy var stepperView = CustomStepper()          \/\/MARK: - Life Cycle     override func viewDidLoad() {         super.viewDidLoad()         setupViews()         setupConstraints()     }          \/\/MARK: - Private     private func setupViews() {         view.backgroundColor = .white         view.addSubview(stepperView)         stepperView.delegate = self     }          private func setupConstraints() {         stepperView.snp.makeConstraints { make in             make.centerX.centerY.equalToSuperview()         }     } }  \/\/MARK: - CustomStepperOutput extension MainVC: CustomStepperOutput {     func customStepper(_ didChangeValue: Int) {         print(didChangeValue)     } }<\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u0412\u043e\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ae4\/a85\/860\/ae4a858600aef8d8c4130491f9f92e65.gif\" width=\"600\" height=\"1300\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ae4\/a85\/860\/ae4a858600aef8d8c4130491f9f92e65.gif\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/701202\/\"> https:\/\/habr.com\/ru\/post\/701202\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/github.com\/zontz\/CustomStepper\" rel=\"noopener noreferrer nofollow\">\u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/a><\/p>\n<p>\u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c stepper, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0438\u0437 \u043d\u0438\u0445 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e Apple \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430, \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u043d \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c. \u042d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438  \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430 \u0434\u043b\u044f \u043a\u043e\u0444\u0435\u0439\u043d\u0438.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0441\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0432 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0438, \u043d\u043e \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0436\u0443 \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0440\u0441\u0442\u043a\u0443 \u043a\u043e\u0434\u043e\u043c, stackView \u0441 2 \u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438 (-,+) \u0438 \u043b\u0435\u0439\u0431\u043b.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0442\u0435\u043f\u043f\u0435\u0440, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 UIView. \u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 UI-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0442\u043e\u043c \u0432\u0437\u044f\u0442\u044c \u0432 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u044b.<\/p>\n<p>\u0421\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435  &#8212; \u043b\u043e\u0433\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043b\u0435\u0439\u0431\u043b\u0430.<\/p>\n<pre><code class=\"swift\">final class CustomStepper: UIView {      private lazy var currentValue = 1 }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c 2 \u043a\u043d\u043e\u043f\u043a\u0438 \u0438 \u043b\u0435\u0439\u0431\u043b,  \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u043d\u0430\u0448 \u0441\u0442\u0435\u043f\u043f\u0435\u0440. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c enum, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u043c\u0438 \u043a\u043d\u043e\u043f\u043e\u043a. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u0435\u0433\u0438,  \u0434\u043b\u044f  \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0434\u0435\u043b\u0430\u0442\u044c 2 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043e\u043a.<\/p>\n<pre><code class=\"swift\">    private enum ButtonState: Int, CaseIterable {         case decrease = 0         case increase     }      private lazy var decreaseButton: UIButton = {         let button = UIButton()         button.tag = ButtonState.decrease.rawValue         button.setTitleColor(.black, for: .normal)         button.setTitle(\"-\", for: .normal)         button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)         return button     }()              private lazy var currentStepValueLabel: UILabel = {         let label = UILabel()         label.textColor = .black         label.text = \"\\(currentValue)\"         label.font = .systemFont(ofSize: 15)         return label     }()              private lazy var increaseButton: UIButton = {         let button = UIButton()         button.tag = ButtonState.increase.rawValue         button.setTitle(\"+\", for: .normal)         button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)         button.setTitleColor(.black, for: .normal)         return button     }()<\/code><\/pre>\n<p>\u0418\u043c\u0435\u044f \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043b\u043e\u0433\u0438\u043a\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430 \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u043a \u043d\u0430\u0448\u0438\u043c \u043a\u043d\u043e\u043f\u043a\u0430\u043c.<\/p>\n<pre><code class=\"swift\">    \/\/MARK: - Actions     @objc private func buttonAction(_ sender: UIButton) {         let buttonState = ButtonState(rawValue: sender.tag)                  switch buttonState {         case .decrease:             currentValue = currentValue > 1 ? currentValue - 1 : currentValue         case .increase:             currentValue += 1         default:             return         }         currentStepValueLabel.text = \"\\(currentValue)\"     }<\/code><\/pre>\n<p>\u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430 \u0432 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"swift\">protocol CustomStepperOutput: AnyObject {     func customStepper(_ didChangeValue: Int) }  protocol CustomStepperInput: AnyObject {     func update(_ value:Int) }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a (\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438)<\/p>\n<pre><code class=\"swift\">\/\/MARK: - CustomStepperInput extension CustomStepper: CustomStepperInput {     func update(_ value: Int) {         currentValue = value     } }<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u0441\u0442\u0435\u043f\u043f\u0435\u0440. \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043f\u043e\u0434\u043f\u0438\u0448\u0435\u043c \u043f\u043e\u0434 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u043c \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430, \u0433\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442  \u0441\u0442\u0435\u043f\u043f\u0435\u0440\u0430. \u0421 \u044d\u0442\u0438\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443.<\/p>\n<pre><code class=\"swift\">import UIKit  final class MainVC: UIViewController {      private lazy var stepperView = CustomStepper()          \/\/MARK: - Life Cycle     override func viewDidLoad() {         super.viewDidLoad()         setupViews()         setupConstraints()     }          \/\/MARK: - Private     private func setupViews() {         view.backgroundColor = .white         view.addSubview(stepperView)         stepperView.delegate = self     }          private func setupConstraints() {         stepperView.snp.makeConstraints { make in             make.centerX.centerY.equalToSuperview()         }     } }  \/\/MARK: - CustomStepperOutput extension MainVC: CustomStepperOutput {     func customStepper(_ didChangeValue: Int) {         print(didChangeValue)     } }<\/code><\/pre>\n<p>\u0413\u043e\u0442\u043e\u0432\u043e! \u0412\u043e\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/701202\/\"> https:\/\/habr.com\/ru\/post\/701202\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-341627","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=341627"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341627\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}