UIImage *minImage = [[UIImage imageNamed:@"slider_minimum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)]; UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)]; UIImage *thumbImage = [UIImage imageNamed:@"sliderhandle.png"]; [[UISlider appearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal]; [[UISlider appearance] setMinimumTrackImage:minImage forState:UIControlStateNormal]; [[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];
2014년 7월 2일 수요일
UISlider 커스텀
이미지의 사이즈에 맞게 slider의 높이 및 thumb 이미지 교체, 및 slider 의 track을 이미지로 대체.
2014년 6월 2일 월요일
Button array에 있는 객체의 속성을 한번에 바꾸는 방법.
예제 1)
[_arrowButtons setValue:@NO forKeyPath:@"userInteractionEnabled"];
예제2)
[self.starImageViews setValue:@NO forKey:@"highlighted"];
2014년 5월 28일 수요일
append items to UITableView or UICollectionView
// from stack overflow with UITableView
// build the index paths for insertion
// since you're adding to the end of datasource, the new rows will start at count
NSMutableArray*indexPaths =[NSMutableArray array];
NSInteger currentCount = self.datasource.count;
for(int i =0; i < dataToAdd.count; i++)
{
[indexPaths addObject:[NSIndexPath indexPathForRow:currentCount+i inSection:0]];
}
// do the insertion
[self.dataSource addObjects:dataToAdd];
// tell the table view to update (at all of the inserted index paths)
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
// in my real code with UICollectionView
- (void)getMoreServerData
{
// 새로운 아이템을 컬렉션의 끝에 추가
NSMutableArray *indexPaths = [NSMutableArray array];
NSInteger currentCount = items.count;
for (int i = 0; i < model.storesModelArray.count; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:currentCount+i inSection:0]];
}
[items addObjectsFromArray:model.storesModelArray];
[self.collectionView insertItemsAtIndexPaths:indexPaths];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// 리스트의 마지막에 도착한 경우 attach data
if (scrollOffset + scrollView.frame.size.height == scrollView.contentSize.height)
{
[self getMoreServerData];
}
}
2014년 5월 17일 토요일
grid crop with uiimage
이미지를 grid 형태로 잘라서 view에 add하는 예제.
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *scaledImage = [self scaleWithImage:[UIImage imageNamed:@"37.jpg"] scaledToSize:self.view.frame.size];
self.originalImageView = [[UIImageView alloc] initWithImage:scaledImage];
[self prepareSlices:10 :10];
}
-(void)prepareSlices:(uint)row :(uint)col
{
float flagX = _originalImageView.image.size.width / _originalImageView.frame.size.width;
float flagY = _originalImageView.image.size.height / _originalImageView.frame.size.height;
float _width = _originalImageView.frame.size.width / col;
float _height = _originalImageView.frame.size.height / row;
float _posX = 0.0;
float _posY = 0.0;
for (int i = 1; i <= row * col; i++) {
UIImageView *croppedImageVeiw = [[UIImageView alloc] initWithFrame:CGRectMake(_posX, _posY, _width, _height)];
UIImage *img = [self getCropImage:CGRectMake(_posX * flagX,_posY * flagY, _width * flagX, _height * flagY)];
croppedImageVeiw.image = img;
croppedImageVeiw.layer.borderColor = [[UIColor whiteColor] CGColor];
croppedImageVeiw.layer.borderWidth = 1.0f;
[self.view addSubview:croppedImageVeiw];
_posX += _width;
if (i % col == 0) {
_posX = 0;
_posY += _height;
}
}
}
-(UIImage*)getCropImage:(CGRect)cropRect
{
CGImageRef image = CGImageCreateWithImageInRect([_originalImageView.image CGImage],cropRect);
UIImage *cropedImage = [UIImage imageWithCGImage:image];
CGImageRelease(image);
return cropedImage;
}
- (UIImage *)scaleWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 1.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
2014년 5월 10일 토요일
UIView가 화면에 추가되서 보여지는지 안보여지고있는지 체크하는 방법
UIView.window를 체크하면 됨.
<예제>
MyUIViewController.h
UIView *popupView;
MyUiViewController.m
..
popupView = [UIView alloc] init];
[self.view addSubView:popupView];
if(popupView.Window != nil)
NSLog(@"you can see popup now");
....
[popupView removeFromSuperView];
if(popupView.Window == nil)
NSLog(@"you can't see popup now");
2014년 5월 9일 금요일
uiview 터시하면 keyboard 사라지게 하는 방법
UIView 의 - (BOOL)endEditing:(BOOL)force 함수를 사용하면 됨.
예제)
MyViewController.m
...
..
예제)
MyViewController.m
...
..
[self.view endEditing:NO];
2014년 5월 2일 금요일
string에서 keyword를 찾아 빨간색으로 표시하기
// search matching keyword
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:searchKeyword
options:NSRegularExpressionCaseInsensitive
error:nil];
[regex enumerateMatchesInString:fullString options:0 range:NSMakeRange(0, [fullString length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop){
[attributedText addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:result.range];
[self.label setAttributedText:attributedText];
}];
피드 구독하기:
글 (Atom)
