패스워드용 텍스트필드를 만들려면 Secure설정을 주면 된다.

 

하지만 이렇게 하면 포커스가 옴겨졌다 다시 텍스트필드를 수정하려고하면 기존 텍스트 내용이 날라간다.

 

보안이 필요한 텍스트필드니 당연하다 생각했는데

 

이걸 원치 않는 사람이 있나보다

 

수정되는 이전 값이 남아 있고, 값이 숨기고 보이고 할 수 있고 그런 텍스트 필드를 원하는데 어떻게 해야할까요?

 

라는 질문을 글을 보고 이렇게 하면 되지 않을까 하고 해봤는데

 

솔직히 별로 맘에 안든다.

 

다른 방법이 없으려나

 

보안이 보안답지 않고....

그렇다고 소스가 깔끔하지도 않고....

 

나중에 텍스트필드를 새로 클래스 만들어서 하면 좀 깔끔해질거같긴한데 

미묘하다.

 

 

https://github.com/wiwi-git/Hide_And_Show_TextField

 

GitHub - wiwi-git/Hide_And_Show_TextField: 포커스 옴겨도 사라지지 않고 숨기고 보이고 할 수 있는 패스워

포커스 옴겨도 사라지지 않고 숨기고 보이고 할 수 있는 패스워드용 텍스트필드가 어떻게 만들까 생각하다 끄적여보는 레포지토리 - GitHub - wiwi-git/Hide_And_Show_TextField: 포커스 옴겨도 사라지지 않

github.com

 

var textField: UITextField!
    var showButton: UIButton!
    private var hiddenText: String = "" {
        didSet{
            print("hiddenText: " + hiddenText)
        }
    }
    var isShowMode = false
    
    let secretChar = "*"
    
    override func viewDidLoad() {
        super.viewDidLoad()
        textField = createTextField()
        showButton = createShowButton()

        view.addSubview(textField)
        view.addSubview(showButton)
        
        let viewGuide = view.safeAreaLayoutGuide
        textField.translatesAutoresizingMaskIntoConstraints = false
        showButton.translatesAutoresizingMaskIntoConstraints = false
        [
            textField.topAnchor.constraint(equalTo: viewGuide.topAnchor, constant: 30),
            textField.leadingAnchor.constraint(equalTo: viewGuide.leadingAnchor, constant: 16),
            textField.trailingAnchor.constraint(equalTo: viewGuide.trailingAnchor,constant: -16),
            textField.heightAnchor.constraint(equalToConstant: textField.frame.height),
            
            showButton.topAnchor.constraint(equalTo: textField.bottomAnchor, constant: 8),
            showButton.trailingAnchor.constraint(equalTo: viewGuide.trailingAnchor,constant: -16),
            showButton.heightAnchor.constraint(equalToConstant: textField.frame.height),
            showButton.widthAnchor.constraint(equalToConstant: 100)
        ].forEach { $0.isActive = true }
    }
    
    func createTextField() -> UITextField {
        let textFieldSize = CGSize(width: 0, height: 35)
        let textField = UITextField(frame: CGRect(origin: .zero, size: textFieldSize))
        textField.layer.borderWidth = 1
        textField.layer.cornerRadius = 10
        textField.textContentType = .password
        textField.placeholder = "password"
        textField.keyboardType = .asciiCapable
        textField.isSelected = false
        
        textField.addTarget(self, action: #selector(textFieldEditingChangedAction(_:)), for: .editingChanged)
        return textField
    }

    func createShowButton() -> UIButton {
        let showButton = UIButton(frame: CGRect(origin: .zero, size: CGSize(width: 100, height: 35)))
        showButton.setTitle("Set Show", for: .normal)
        showButton.setTitleColor(.systemBlue, for: .normal)
        showButton.backgroundColor = .clear
        showButton.setBackgroundImage(nil, for: .normal)
        showButton.layer.borderWidth = 1
        showButton.layer.borderColor = UIColor.systemBlue.cgColor
        showButton.layer.cornerRadius = 10
        showButton.addTarget(self, action: #selector(showButtonAction(_:)), for: .touchUpInside)
        
        return showButton
    }
    
    @objc func showButtonAction(_ sender: UIButton) {
        if ( sender.titleLabel?.text == "Set Show") {
            self.isShowMode = true
            sender.setTitle("Set Hide", for: .normal)
            sender.layer.borderColor = UIColor.clear.cgColor
            sender.backgroundColor = .darkGray
            sender.setTitleColor(.white, for: .normal)
            
            self.textField.text = hiddenText
            
        } else {
            self.isShowMode = false
            sender.setTitle("Set Show", for: .normal)
            sender.setTitleColor(.systemBlue, for: .normal)
            sender.backgroundColor = .clear
            sender.layer.borderColor = UIColor.systemBlue.cgColor
            
            textField.text = ""
            hiddenText.forEach { _ in
                textField.text! += secretChar
            }
        }
    }
    
    @objc func textFieldEditingChangedAction(_ textField: UITextField) {
        guard let last = textField.text?.last else {
            hiddenText = ""
            return
        }
        
        if textField.text?.count ?? 0 > hiddenText.count {
            if (!isShowMode) {
                textField.text?.removeLast()
                textField.text! += secretChar
            }
            hiddenText += String(last)
        } else {
            hiddenText.removeLast()
        }
    }
반응형

Attempted to scroll the collection view to an out-of-bounds item (0) when there are only 0 items in section 0.

 

늦은 업데이트를 진행하였고 시뮬레이터가 15.2가 되었다.

회사 프로젝트를 돌려보던중 시뮬레이터에서 위와 같은 에러가 나면서 종료가 되고있다.

 

내용만 봐선 "아이템이 0인데 스크롤을 0으로 하려고한다 그러지마 "  라며 친절히 문제되는 부분을 알려주지만

 

이전에는 됐는데?

 

참담한 심정으로 콜렉션뷰의 스크롤하는 부분

      self.collectionView.scrollToItem

부분을

if (.count != 0 ) 를 걸어주어 0 이후에 변경될때만 호출해주도록 변경하였다.

 

동작은 한다

 

뭔가 미묘한 기분

반응형

https://www.viget.com/articles/animated-ios-launch-screen/

 

Animate Your iOS Splash Screen | Viget

Learn how to animate iOS launch screens however you want!

www.viget.com

 

반응형

https://github.com/raywenderlich/swift-algorithm-club

반응형

https://github.com/morizotter/KeyboardObserver

 

GitHub - morizotter/KeyboardObserver: For less complicated keyboard event handling.

For less complicated keyboard event handling. Contribute to morizotter/KeyboardObserver development by creating an account on GitHub.

github.com

 

매번 Notification으로 받고 하는게 뭔가 안좋아보여서 참고할 오픈소스....

 

나중에 보자

반응형

https://xho95.github.io/swift/programming/language/grammar/2017/02/28/The-Swift-Programming-Language.html

 

Swift 5.5: Swift Programming Language (스위프트 프로그래밍 언어)

 

xho95.github.io

애플 공식 swift 5.5 문서를 번역하는 블로그.

반응형

'iOS > swift' 카테고리의 다른 글

메모. 스위프트 알고리즘  (0) 2022.01.12
KeyboardObserver~  (0) 2021.10.19
UIPickerView 의 텍스트 색상 변경하는 방법  (0) 2021.06.17
프로그래머스 - 프린터  (0) 2021.05.06
프로그래머스 - 기능개발  (0) 2021.05.05

https://khushwanttanwar.medium.com/xcode-12-compilation-errors-while-running-with-ios-14-simulators-5731c91326e9

 

Xcode 12 Compilation Errors (While running with iOS 14 Simulators)

Migrating to the latest Version 12.0.1 (12A7300) version, while compiling the running project, it gives errors with simulator selected…

khushwanttanwar.medium.com

 

 

m1 mac mini로 기존 프로젝트들이 돌아가는지 테스트중에 

해당 문제가 발생했다.

 

해결은 아래와같이 했다.

  • To do that for Main Project, navigate to Build Settings of your project and add Any iOS Simulator SDK with value arm64 inside Excluded Architecture. (Note: Project, not Target. Adding to Project will automatically add settings to all its Target)

 

감사 그자체

 

반응형

88. 콘솔에서 네 개의 정수( a, m, d, n )를 입력받고, a를 시작값 으로갖고 m을 곱하고 d 를 더한 값이 다음값으로 갖는 수열의 n번째 수를 출력하라.

( ex : a , a*m+d, (a*m+d)*m+d, ....)

입력: 1Line 에 공백을 두고 4개의 정수가 입력됨

입력 범위 : a,m,d : -50 ~ 50, n: 1 ~ 10​

입력 예시

1 -2 1 8

출력 예시

-85

JAVA

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int startNum = scan.nextInt();
		int mulNum = scan.nextInt();
		int addNum = scan.nextInt();
		int targetIndex = scan.nextInt();
		scan.close();
		
		int result = startNum;
		for (int i = 1; i < targetIndex; i++) {
			result *= mulNum;
			result += addNum;
		}
		
		System.out.println(result);
	}
}

Swift 4.2

import Foundation

if let line = readLine(){
    let valueArray = line.split(separator: " ")
    if valueArray.count == 4,
        let startNum = Int(valueArray.first!),
        let mulNum = Int(valueArray[1]),
        let addNum = Int(valueArray[2]),
        let targetIndex = Int(valueArray[3])
    {
        var result = startNum
        for _ in 1 ..< targetIndex {
            result *= mulNum
            result += addNum
        }
        print(result)
    }
}

이전 코드에서 덧셈부분만 추가됏습니다.

음... 수학문제도 프로그래밍으로 풀수있다! 라는걸 알려주려고 낸 문제였을까요?

https://codeup.kr/problem.php?id=1091

 

 

반응형

+ Recent posts