2020. 5. 20. 14:52ㆍ아이폰 개발
커스텀 View에서 이미지 출력시 뒤집어질 경우 처리 방법
extension CGContext {
/// Draw `image` flipped vertically, positioned and scaled inside `rect`.
public func drawFlipped(_ image: CGImage, in rect: CGRect) {
self.saveGState()
self.translateBy(x: 0, y: rect.origin.y + rect.height)
self.scaleBy(x: 1.0, y: -1.0)
self.draw(image, in: CGRect(origin: CGPoint(x: rect.origin.x, y: 0), size: rect.size))
self.restoreGState()
}
}
ctx.drawFlipped(myImage, in: myRect)
CGContextDrawImage draws image upside down when passed UIImage.CGImage
Does anyone know why CGContextDrawImage would be drawing my image upside down? I am loading an image in from my application: UIImage *image = [UIImage imageNamed:@"testImage.png"]; And then simply
stackoverflow.com
파일명과 확장자 추출하는 방법
extension String {
func lastPathComponent(withExtension: Bool = true) -> String {
let lpc = self.nsString.lastPathComponent
return withExtension ? lpc : lpc.nsString.deletingPathExtension
}
var nsString: NSString {
return NSString(string: self)
}
}
let path = "/very/long/path/to/filename_v123.456.plist"
let filename = path.lastPathComponent(withExtension: false)
ios — Swift의 파일 확장자에서 파일 이름을 분리하는 방법은 무엇입니까?
이것은 Swift 2, Xcode 7 :입니다. 확장자가 이미 붙은 파일 이름이 있으면 첫 번째 매개 변수로 전체 파일 이름을 전달하고 두 번째 매개 변수로 빈 문자열을 전달할 수 있습니다 : let soundURL = NSBundle.
www.it-swarm.dev
UIImage 리사이즈 하는 방법
extension UIImage {
func resized(to size: CGSize) -> UIImage {
return UIGraphicsImageRenderer(size: size).image { _ in
draw(in: CGRect(origin: .zero, size: size))
}
}
}
let resizedImage = image.resized(to: CGSize(width: 50, height: 50))
https://stackoverflow.com/questions/2658738/the-simplest-way-to-resize-an-uiimage
The simplest way to resize an UIImage?
In my iPhone app, I take a picture with the camera, then I want to resize it to 290*390 pixels. I was using this method to resize the image : UIImage *newImage = [image _imageScaledToSize:CGSize...
stackoverflow.com
탭바를 프로그램에서 전환하는 방법
func switchToDataTab(){
NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: #selector(switchToDataTabCont), userInfo: nil,repeats: false)
}
func switchToDataTabCont(){
tabBarController!.selectedIndex = 0
}
https://stackoverflow.com/questions/28099148/switch-tab-bar-programmatically-in-swift
Switch tab bar programmatically in Swift
I have a tab bar application and i have a button on my first view which i want to when pressed switch to my second tab programmatically in the tab bar. I can't quite seem to figure it out how to g...
stackoverflow.com
컬렉션뷰 구현 방법
https://www.raywenderlich.com/9334-uicollectionview-tutorial-getting-started
UICollectionView Tutorial: Getting Started
In this tutorial, you’ll get hands-on experience with UICollectionView by creating your own grid-based photo browsing app.
www.raywenderlich.com
https://www.journaldev.com/10678/ios-uicollectionview-example-tutorial
iOS UICollectionView Example Tutorial - JournalDev
UICollectionView tutorial, iOS UICollectionView example, UICollectionView Objective C, Swift UICollectionView, Collection View iOS app example code project.
www.journaldev.com