2017-03-16 3 views
0

문단에 텍스트를 더 자세히 읽고/less than 추가하는 데 문제가 있습니다. 그 텍스트는 아이포드에는 필요하지만 아이 패드는 필요 없다. 아래 첨부 된 이미지를보십시오.
추가 방법 Swift 3 단락에서 더 많거나 적은 것을 읽으시겠습니까?

enter image description here


첫 번째 문제 내가 '자세히 알아보기'버튼을 클릭하기 전에, 왼쪽 상단 모서리에 공간 있다는 것입니다. Read More 버튼을 클릭하면 레이블이 위로 이동하고 공백이 없습니다입니다.

초 문제는 화면 크기가 크고 모든 텍스트가 표시되기 때문에 장치가 아이 패드
경우을 필요로하지 않습니다 자세히 버튼을 읽습니다.
의 경우 해당 버튼이 있어야합니다.
enter image description here



여기 내 코드입니다. 읽기 버튼이 필요하거나없는 경우

func getLabelHeight(text: String, width: CGFloat, font: UIFont) -> CGFloat { 
    let lbl = UILabel(frame: .zero) 
    lbl.frame.size.width = width 
    lbl.font = font 
    lbl.numberOfLines = 0 
    lbl.text = text 
    lbl.sizeToFit() 

    return lbl.frame.size.height 
} 

@IBAction func btnReadMore(_ sender: Any) { 
    if isLabelAtMaxHeight { 
     btnReadmore.setTitle("Read more", for: .normal) 
     isLabelAtMaxHeight = false 
     lblReviewHeight.constant = 93 
    } 
    else { 
     btnReadmore.setTitle("Read less", for: .normal) 
     isLabelAtMaxHeight = true 
     lblReviewHeight.constant = getLabelHeight(text: lblReview.text!, width: view.bounds.width, font: lblReview.font) 

    } 

} 

어떻게 이것을 확인할 수 있습니까? 도와주세요. 다른 라이브러리 파일을 추가하고 싶지 않습니다.

답변

0

당신은 다음 코드를 사용하여 장치를 식별 할 수

import UIKit 

public extension UIDevice { 

    var modelName: String { 
     var systemInfo = utsname() 
     uname(&systemInfo) 
     let machineMirror = Mirror(reflecting: systemInfo.machine) 
     let identifier = machineMirror.children.reduce("") { identifier, element in 
      guard let value = element.value as? Int8, value != 0 else { return identifier } 
      return identifier + String(UnicodeScalar(UInt8(value))) 
     } 

     switch identifier { 
     case "iPod5,1":         return "iPod Touch 5" 
     case "iPod7,1":         return "iPod Touch 6" 
     case "iPhone3,1", "iPhone3,2", "iPhone3,3":  return "iPhone 4" 
     case "iPhone4,1":        return "iPhone 4s" 
     case "iPhone5,1", "iPhone5,2":     return "iPhone 5" 
     case "iPhone5,3", "iPhone5,4":     return "iPhone 5c" 
     case "iPhone6,1", "iPhone6,2":     return "iPhone 5s" 
     case "iPhone7,2":        return "iPhone 6" 
     case "iPhone7,1":        return "iPhone 6 Plus" 
     case "iPhone8,1":        return "iPhone 6s" 
     case "iPhone8,2":        return "iPhone 6s Plus" 
     case "iPhone9,1", "iPhone9,3":     return "iPhone 7" 
     case "iPhone9,2", "iPhone9,4":     return "iPhone 7 Plus" 
     case "iPhone8,4":        return "iPhone SE" 
     case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4":return "iPad 2" 
     case "iPad3,1", "iPad3,2", "iPad3,3":   return "iPad 3" 
     case "iPad3,4", "iPad3,5", "iPad3,6":   return "iPad 4" 
     case "iPad4,1", "iPad4,2", "iPad4,3":   return "iPad Air" 
     case "iPad5,3", "iPad5,4":      return "iPad Air 2" 
     case "iPad2,5", "iPad2,6", "iPad2,7":   return "iPad Mini" 
     case "iPad4,4", "iPad4,5", "iPad4,6":   return "iPad Mini 2" 
     case "iPad4,7", "iPad4,8", "iPad4,9":   return "iPad Mini 3" 
     case "iPad5,1", "iPad5,2":      return "iPad Mini 4" 
     case "iPad6,3", "iPad6,4", "iPad6,7", "iPad6,8":return "iPad Pro" 
     case "AppleTV5,3":        return "Apple TV" 
     case "i386", "x86_64":       return "Simulator" 
     default:          return identifier 
     } 
    } 

} 

// 스위프트 3 는 MODELNAME = UIDevice.current.modelName이

그런 다음 다른, 경우에 사용할 수 있도록 (here에서 그것을 얻을).

if(modelName == iPad 3 || modelName == iPad 4 ||modelName == iPad Air){ 

    // No Read More button 

}else{ 
    // Add Read More button 
}