UIGraphicsBeginImageContext(image.size); CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy); [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference); CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor); CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.size.width, image.size.height)); UIImage *returnImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
Category Archives: Мобильные платформы
iOS: Отключить автоматическую блокировку экрана/спящий режим
[UIApplication sharedApplication].idleTimerDisabled = !lockscreenEnabled;
UIBarButtonItem
Кнопка в тулбаре/навбаре с красивой иконкой.
UIImage *faceImage = [UIImage imageNamed:(screenLocked) ? @"Locked" : @"Unlocked"];
UIButton *lockBt = [UIButton buttonWithType:UIButtonTypeCustom];
lockBt.bounds = CGRectMake(0, 0, faceImage.size.width, faceImage.size.height);
[lockBt setImage:faceImage forState:UIControlStateNormal];
[lockBt addTarget:self action:@selector(lockScreen:) forControlEvents:UIControlEventTouchUpInside];
lockButton = [[UIBarButtonItem alloc] initWithCustomView:lockBt];
Спрятать UITabBar программно
#import "UITabBarController+ShowHideBar.h"
@implementation UITabBarController (ShowHideBar)
- (void) setHidden:(BOOL)hidden{
CGRect screenRect = [[UIScreen mainScreen] bounds];
float fHeight = screenRect.size.height;
if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ){
fHeight = screenRect.size.width;
}
if(!hidden) fHeight -= self.tabBar.frame.size.height;
[UIView animateWithDuration:0.25 animations:^{
for(UIView *view in self.view.subviews){
if([view isKindOfClass:[UITabBar class]]){
[view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
}else{
if(hidden) [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
}
}
}completion:^(BOOL finished){
if(!hidden){
[UIView animateWithDuration:0.25 animations:^{
for(UIView *view in self.view.subviews)
{
if(![view isKindOfClass:[UITabBar class]])
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
}
}];
}
}];
}
@end
UIAccessibilityIsInvertColorsEnabled
Удобная функция универсального доступа — инверсия цветов, для ночного чтения.
Проверить активность данного режима просто: UIAccessibilityIsInvertColorsEnabled, но вот программно активировать — API нет =(
Прийдется опять изобретать велосипед…
Проблема — отображение PDF в «ночном режиме» чтения (белое на чёрном).
Борьба с Зомби! -[UISearchDisplayController _destroyManagedTableView]
Оказывается очень мощный и полезный инструмент Profiler…
http://stackoverflow.com/questions/9853100/getting-info-about-bad-memory-address-in-lldb
dyld: Symbol not found: _NSURLIsExcludedFromBackupKey
Получил такую ошибку при попытки запуска проекта на iOS 5.0 Simulator.
Погуглив, выяснилось в основном такая проблема возникает у тех, кто реально использует этот символ.
Предлагается следующее решение:
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
const char* filePath = [[URL path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";
if (&NSURLIsExcludedFromBackupKey == nil) {
// iOS 5.0.1 and lower
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
} else {
// First try and remove the extended attribute if it is present
int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
if (result != -1) {
// The attribute exists, we need to remove it
int removeResult = removexattr(filePath, attrName, 0);
if (removeResult == 0) {
NSLog(@"Removed extended attribute on file %@", URL);
}
}
// Set the new key
return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}
}
Но в моем проекте он совершенно не использовался и в подключенных фреймворках тоже.
Решение как всегда неочевидное но очень простое — подключить CoreFoundation.framework и сделать его Optional.
DiskImageCache: Could not resolve the absolute path of the old directory
Приложение странно падает при загрузке PDF с файловой системы.
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath: filename]];
[webView loadRequest:urlRequest];
[/code]
Отправка СМС через приложение
if ( [[[UIDevice currentDevice] systemVersion] doubleValue ] >= 4.0 )
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = str;
controller.recipients = nil;
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
}
Убрать Deprecated сообщение
if ( [[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2 ) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated" [[userInfo objectForKey:UIKeyboardBoundsUserInfoKey] getValue:&keyboardEndFrame]; #pragma GCC diagnostic pop else [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];