enum {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
typedef NSUInteger UIViewAutoresizing;
Mostrando postagens com marcador Objective-C. Mostrar todas as postagens
Mostrando postagens com marcador Objective-C. Mostrar todas as postagens
sexta-feira, 20 de julho de 2012
Enum - Bit Operators
quarta-feira, 11 de julho de 2012
Objective-C em expansão
Pessoal, a linguagem de programação a que este blog se dedica está em franco crescimento.
Fonte: Tiobe
quarta-feira, 4 de julho de 2012
Função - Retorna uma NSString (hh:mm:ss) passando apenas os segundos
Função que retorna uma string (NSString) no formato de horário apenas passando a quantidade de segundos.
Barbada galera!
Barbada galera!
- {
- int hour = 0, min = 0, sec = 0;
- sec = seconds;
- while (sec >= 60) {min+=1; sec-=60;}
- while (min >= 60) {hour+=1; min-=60;}
- }
sexta-feira, 29 de junho de 2012
Função - Redimensionar UIImage
Função para redimensionar imagens (UIImage).
- +(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
- {
- UIGraphicsBeginImageContext(newSize);
- [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
- UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return newImage;
- }
segunda-feira, 25 de junho de 2012
Função - Embaralhar NSMutableArray
Função para você embaralhar um NSMutableArray um determinado número de vezes.
- //Aplicação do método
- NSMutableArray * array = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", nil];
- [self shuffleMutableArray:&array frequency:10];
- //Método para embaralhar arrays
- {
- for (int i = 0; i < f; i++) {
- int randA,randB;
- do {
- randA = (random() % [*array count] -i)+i;
- randB = (random() % [*array count] -i)+i;
- } while (randA==randB);
- [*array exchangeObjectAtIndex:randA withObjectAtIndex:randB];
- }
- }
quarta-feira, 14 de março de 2012
Dica - Saber quando a UITableView está sendo movimentada (Scrolling)
Pessoal,
Este código é para vocês saberem quando a UITableView está sendo movimentada (Scrolling). Ou seja, o cidadão começou a rolar a tabela para baixo e você quer ter os mesmos Delegates que o UIScrollView.
Sabendo que o UITableView herda de UIScrollView... segue o código:
Este código é para vocês saberem quando a UITableView está sendo movimentada (Scrolling). Ou seja, o cidadão começou a rolar a tabela para baixo e você quer ter os mesmos Delegates que o UIScrollView.
Sabendo que o UITableView herda de UIScrollView... segue o código:
- //In ViewController.h
- #import <UIKit/UIKit.h>
- @interfaceViewController:UIViewController<UIScrollViewDelegate>
- {
- IBOutletUITableView* myTable;
- IBOutletUIScrollView* myScroll;
- }
- //In ViewController.m
- #pragma mark -View lifecycle
- -(void)viewDidLoad{
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- myScroll = myTable;
- myScroll.delegate = self;
- }
- #pragmaMarkUIScrollViewDelegate
- -(void)scrollViewDidScroll:(UIScrollView*)scrollView{
- NSLog(@"%f",scrollView.contentOffset.y);
- }
sexta-feira, 24 de fevereiro de 2012
quinta-feira, 15 de dezembro de 2011
sábado, 10 de dezembro de 2011
Função - Formatar horário a partir de X segundos
// ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Criando um processo para chamar o métodos onTimer a cada 1 segundo
[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}
- (void)onTimer
{
static int segundos = 0;
segundos++;
// Imprimi no console o horário formatado
NSLog(@"%@",[self horarioFormatadaComSegundos:segundos]);
}
// Função para formatar um horário a partir de inteiros.
- (NSString *)horarioFormatadaComSegundos:(int)segundos
{
int hor = 0, min = 0, seg = 0;
seg = segundos;
while (seg >= 60) { min+=1; seg-=60; }
while (min >= 60) { hor+=1; min-=60; }
NSString * h, * m, * s;
h = (hor > 9) ? [NSString stringWithFormat:@"%d",hor] : [NSString stringWithFormat:@"0%d",hor] ;
m = (min > 9) ? [NSString stringWithFormat:@"%d",min] : [NSString stringWithFormat:@"0%d",min] ;
s = (seg > 9) ? [NSString stringWithFormat:@"%d",seg] : [NSString stringWithFormat:@"0%d",seg] ;
return [NSString stringWithFormat:@"%@:%@:%@",h,m,s];
}
Cantos Arredondados nas Imagens, Botões, e etc.
Adicionar o seguinte framework ao projeto:
// Declarar no header
#import <QuartzCore/QuartzCore.h>
// Código
- (void)viewDidLoad
{
[super viewDidLoad];
// Criando uma imagem
CGRect rect = CGRectMake((self.view.frame.size.width/2)-57, (self.view.frame.size.height/2)-90, 114, 175);
UIImageView * image = [[UIImageView alloc] initWithFrame:rect];
[image setImage:[UIImage imageNamed:@"bio.jpg"]];
// Modificando os cantos
image.layer.cornerRadius = 20.0f;
image.layer.masksToBounds = YES;
// Adicionando a imagem na tela
[self.view addSubview:image];
[image release]; image = nil;
}
=================================================================================
Resultado:
Download: _CantosArredondados.zip
Adicionando Sombra nas Imagens
Adicionar o seguinte framework ao projeto:
// Declarar no header
#import <QuartzCore/QuartzCore.h>
// Código
- (void)viewDidLoad
{
[super viewDidLoad];
// Criando uma imagem
CGRect rect = CGRectMake(10, 20, 280, 428);
UIImageView * image = [[UIImageView alloc] initWithFrame:rect];
[image setImage:[UIImage imageNamed:@"bio.jpg"]];
// Adicionando a Sombra
image.layer.shadowColor = [UIColor grayColor].CGColor;
image.layer.shadowOffset = CGSizeMake(2, -2);
image.layer.shadowOpacity = 1;
image.layer.shadowRadius = 1.0;
// Adicionando a imagem na tela
[self.view addSubview:image];
[image release]; image = nil;
}
=================================================================================
Resultado:
Download: _ImagemComSombra.zip
terça-feira, 29 de novembro de 2011
Função - Gerando números aleatórios
srand(time(NULL)); // Sequência que nunca se repete
for (int i = 0; i < 10; i++)
{
int r = rand()%100; // Gerando número aleatório de 0 à 100.
NSLog(@"%d",r); // Imprimindo resposta
}
srand(100); // Sequência que sempre se repete
for (int i = 0; i < 10; i++)
{
int r = rand()%100; // Gerando número aleatório de 0 à 100.
NSLog(@"%d",r); // Imprimindo resposta
}
Assinar:
Postagens (Atom)