This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Всем привет! | |
Сегодня мы научимся изменять цвет StatusBar в целом приложении и для каждого контроллера в отдельности с помощью statusBarStyle. statusBarStyle, отвечает за стиль StatusBar и может иметь одно из двух значений, первое default - это темный стиль (черный цвет), второе lightContent - светлый стиль (белый цвет). Начнем с установки цвета StatusBar во всем проекте. Здесь есть два варианта, первый - самый простой: | |
1. Перейдите в настройки проекта. | |
2. Опуститесь в Deployment info и измените параметр Status Bar Style на нужный. | |
Это самый простой вариант изменения цвета во всем проекте, перейдем ко второму: | |
1. Перейдите в файл info.plist. Этот файл является списком свойств Вашего проекта. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 190 | |
yourLabelName.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2) | |
// 180 | |
yourLabelName.transform = CGAffineTransform(rotationAngle: CGFloat.pi) | |
// -90 | |
yourLabelName.transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { | |
self.view.endEditing(true) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Всем привет! | |
Сегодня мы научимся создавать градиент и применять его к UIView. Приступим! | |
1. Создаем проект. На Main.storyboard создаем UIView и задаем ей Constraint с помощью Auto Layout | |
2. Открываем редактор кода и создаем связь между UIView и кодом с помощью @IBOutlet (имя задаем любое, например myView) | |
3. Открывает файл ViewController со связью и переходим к методу viewDidLoad. | |
4. Внутри метода: | |
4.1. Создаем слой градиента с помощью CAGradientLayer. CAGradientLayer - это слой, который рисует цветовой градиент над цветом фона, заполняя форму слоя: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Всем привет! | |
Сегодня мы научимся программно заменять все символы в строке и/или тексте. Бывает такое, что у Вас есть длинный текст в котором нужно заменить все символы, но делать это вручную долго. | |
Сделать это можно с помощью replacingOccurrences. С помощью replacingOccurrences можно вернуть новую строку, в которой все символы целевой строки в указанном диапазоне заменяются на другой. Например: | |
Создаем текст и создаем новую строку с replacingOccurrences: | |
let sourceString = "Это моя первая текстовая строка" | |
let newString = sourceString.replacingOccurrences(of: " ", with: "+", options: .literal, range: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Всем привет! | |
Сегодня мы научимся сохранять фотографию в Photo Library. Для достижения данной цели мы воспользуемся Библиотекой Photos, для этого переходим в файл ViewController (или свой) и импортируем ее: | |
import Photos | |
Ниже в классе создадим константку для фотографии: | |
let snapshot: UIImage = someImage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Всем привет! | |
Сегодня мы научимся создавать программно задержку. Для достижения данной цели мы воспользуемся DispatchQueue.main - основной очередью. Пишем конструкцию: | |
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { // Изменить `2.0` на нунжное количество секунд. | |
// Здесь указываем что задерживаем | |
} | |
указываем время, на которое нужно произвести задержку и открываем кавычки. Внутри указываем, что задерживаем и закрываем кавычки. asyncAfter - в этой конструкции означает, что произойдет все в фоновом потоке и обновит основной поток через некоторое время, которое мы укажем. Итоговая конструкция выглядит так: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if UIDevice().userInterfaceIdiom == .pad { | |
switch UIScreen.main.nativeBounds.height { | |
case 2048: | |
// iPad Air 2, Pro 9,7 | |
case 2224: | |
// iPad Pro 10,5 | |
case 2388: | |
// iPad Pro 11 | |
case 2732: | |
// iPad Pro 12,9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if UIDevice().userInterfaceIdiom == .phone { | |
switch UIScreen.main.nativeBounds.height { | |
case 1334: | |
// iPhone 6,7,8, 6S, 7S, 8S | |
case 1920,2208: | |
// iPhone 8Plus | |
case 2436: | |
// iPhone X, XS | |
case 2688: | |
// iPhone XS Max |
NewerOlder