Animated Ios Splash screen - objective-c

I'm trying to make my splash screen display 3 images after each other.
Ive tried multiple things but keep running into errors if anyone could see what i'm doing wrong in my code here?
#interface CydiaLoadingViewController : UIViewController
#end
%hook CydiaLoadingViewController
-(void)loadView {
%orig;
UIView *xiView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
xiView.backgroundColor = [UIColor whiteColor];
UIImage *image1 = [UIImage imageNamed:#"image1.png"];
UIImage *image2 = [UIImage imageNamed:#"image2.png"];
UIImage *image3 = [UIImage imageNamed:#"image3.png"];
UIImageView *logo =[[NSArray alloc] initWithObjects:image1,image2,image3, nil];
logo.imageView.animationRepeatCount = 7;
[logo.imageView startAnimating];
logo.frame = CGRectMake([UIScreen mainScreen].bounds.size.width / 2 - 60, [UIScreen mainScreen].bounds.size.height / 2 - 90, 120, 120);
logo.layer.masksToBounds = YES;
logo.layer.cornerRadius = 10;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height / 2 + 60, [UIScreen mainScreen].bounds.size.width, 40)];
label.text = #"Cydia";
label.textAlignment = NSTextAlignmentCenter;
[label setFont:[UIFont boldSystemFontOfSize:30]];\
[xiView addSubview:logo];
[xiView addSubview:label];
[[self view] addSubview:xiView];
}
-(BOOL)hidesNavigationBar {
return YES;
}
%end
the error
Tweak.xm:92:14: error: cannot initialize a variable of type 'UIImageView *' with an
rvalue of type 'NSArray *'
UIImageView *logo =[[NSArray alloc] initWithObjects:image1,image2,image3, nil];

The error is because you assigned an instance of NSArray to an UIImageView variable at this line.
UIImageView *logo =[[NSArray alloc] initWithObjects:image1,image2,image3, nil];
As I understand, you want to use UIImageView to present these 3 images one by one. In this case, you should create UIImageView normally and use UIImageView's animationImages property.
For example
UIImageView *logo = [[UIImageView alloc] init];
logo.animationImages = [[NSArray alloc] initWithObjects:image1,image2,image3, nil];

Related

objective-c ios auto layout NSLayoutConstraint

UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(8, 8, frameWidth, frameHeight)];
headerView.backgroundColor = UIColorFromRGB(0x5F70B9);
UIImage* leftImage = [UIImage imageNamed: #"search_list"];
UIImageView* leftImageView = [[UIImageView alloc] initWithImage: leftImage];
[leftImageView setFrame: CGRectMake(10, 15, 70, 50)]; // CGRectMake(10, 15, 70, 50)
UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(80, 20, 160, 40)];
textView.backgroundColor = UIColorFromRGB(0x5F70B9);
textView.textColor = UIColorFromRGB(0xFFFFFF);
[textView setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleTitle3]];
textView.text = STLocalizedString(#"message_overall_non_reply");
textView.editable = NO;
UIImage* rightImage = [UIImage imageNamed: #"arrow_mask"];
UIImageView* rightImageView = [[UIImageView alloc] initWithImage: rightImage];
[rightImageView setFrame:CGRectMake(380, 30, 15, 20)];
[headerView addSubview: leftImageView];
[headerView addSubview: textView];
[headerView addSubview: rightImageView];
Expect image:
enter image description here
Now i am hardcoding the origin x, y and everything. I want to use auto layout so that the left image and right image act as leading and trailing icon.
any suggestion?
Tried something like below, but not working:
`
[leftImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
NSLayoutConstraint *leftImageViewConstraint = [NSLayoutConstraint constraintWithItem: leftImage attribute: NSLayoutAttributeLeading relatedBy: NSLayoutRelationEqual toItem: headerView attribute: NSLayoutAttributeLeading multiplier: 1 constant: 0];
[leftImageView addConstraints: #[leftImageViewConstraint]];
`
You need to activate each constraint that you add. When you have a bunch of constraints to set it's a lot easier to use NSLayoutConstraint activateConstraints. And using the various "anchor" properties for setting up the constraints is simpler than using the long form of creating an NSLayoutConstraint.
Here's your code updated with lots of constraints:
UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(8, 8, frameWidth, frameHeight)];
headerView.backgroundColor = UIColorFromRGB(0x5F70B9);
UIImage* leftImage = [UIImage imageNamed: #"search_list"];
UIImageView* leftImageView = [[UIImageView alloc] initWithImage: leftImage];
UITextView* textView = [[UITextView alloc] initWithFrame:CGRectZero];
textView.backgroundColor = UIColorFromRGB(0x5F70B9);
textView.textColor = UIColorFromRGB(0xFFFFFF);
textView.font = [UIFont preferredFontForTextStyle:UIFontTextStyleTitle3];
textView.text = STLocalizedString(#"message_overall_non_reply");
textView.editable = NO;
UIImage* rightImage = [UIImage imageNamed: #"arrow_mask"];
UIImageView* rightImageView = [[UIImageView alloc] initWithImage: rightImage];
leftImageView.translatesAutoresizingMaskIntoConstraints = NO;
textView.translatesAutoresizingMaskIntoConstraints = NO;
rightImageView.translatesAutoresizingMaskIntoConstraints = NO;
[headerView addSubview: leftImageView];
[headerView addSubview: textView];
[headerView addSubview: rightImageView];
[NSLayoutConstraint activateConstraints:#[
[leftImageView.leadingAnchor constraintEqualToAnchor:headerView.leadingAnchor constant:10],
//[leftImageView.topAnchor constraintEqualToAnchor:headerView.topAnchor constant:15],
[leftImageView.centerYAnchor constraintEqualToAnchor:headerView.centerYAnchor],
[leftImageView.widthAnchor constraintEqualToConstant:70],
[leftImageView.heightAnchor constraintEqualToConstant:50],
[rightImageView.trailingAnchor constraintEqualToAnchor:headerView.trailingAnchor constant:-10],
//[rightImageView.topAnchor constraintEqualToAnchor:headerView.topAnchor constant:30],
[rightImageView.centerYAnchor constraintEqualToAnchor:headerView.centerYAnchor],
[rightImageView.widthAnchor constraintEqualToConstant:15],
[rightImageView.heightAnchor constraintEqualToConstant:20],
[textView.leadingAnchor constraintEqualToAnchor:leftImageView.trailingAnchor constant:10],
[textView.trailingAnchor constraintEqualToAnchor:rightImageView.leadingAnchor constant:-10],
[textView.topAnchor constraintEqualToAnchor:headerView.topAnchor constant:20],
[textView.bottomAnchor constraintEqualToAnchor:headerView.bottomAnchor constant:-20],
]];
I made a few guesses here. Obviously you can change these to suit your needs.

Content in Table cell of iOS 8 is not display

Everything works well in iOS 9.
But in iOS 8, the content is not displayed, only imageview is showed.
What i did is that I create a view and add label and UIImage to that view. Then that view is added to contentView of table Cell
create View
- (UIView *)getHeaderView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, HEADER_SECTION_HEIGHT)];
[view setBackgroundColor:[[RNThemeManager sharedManager] colorWithHexString:[_themeComponent valueForKey:#"Layer1Color"]]];
UILabel *taskName = [[UILabel alloc] initWithFrame:CGRectMake(5.0, SECTION_BREAK+3.0, view.frame.size.width-23.0, 20)];
[taskName setFont:[UIFont boldSystemFontOfSize:[[_themeComponent valueForKey:#"RegularFontSize"] intValue]]];
[taskName setText:combinedTask.taskDescription];
[taskName setTextColor: [[RNThemeManager sharedManager] colorWithHexString:[_themeComponent valueForKey:#"textPrimary"]]];
[view addSubview:taskName];
UIImageView *addressView = [[UIImageView alloc]initWithFrame:CGRectMake(5.0, SECTION_BREAK+28.0, 20, 20)];
addressView.image = [UIImage imageNamed:[NSString stringWithFormat:#"%#.png", #"Attr_Pin"]];
[view addSubview:addressView];
UILabel *address = [[UILabel alloc] initWithFrame:CGRectMake(35.0, SECTION_BREAK+23.0, view.frame.size.width-35.0, 30)];
[address setFont:[UIFont boldSystemFontOfSize:[[_themeComponent valueForKey:#"SmallFontSize"] intValue]]];
address.lineBreakMode = NSLineBreakByWordWrapping;
address.numberOfLines = 0;
[address setText:[NSString stringWithFormat:#"%#", unit]];
[address setTextColor: [[RNThemeManager sharedManager] colorWithHexString:[_themeComponent valueForKey:#"textPrimary"]]];
[view addSubview:address];
return view;
}
Add view to table cell
UIView *header= [self getHeaderView:tableView viewForHeaderInSection:section];
cell.taskIdLabel.hidden = YES;
[cell.contentView addSubview:header];
Anyone has any ideas? Thanks much for your help.
This is because iOS 9 Apple handle good autolayout than before.
Let add [cell layoutIfNeeded] before return cell.
Update
I have same problem before. Here is block of code that i use to solved my problem.
- (void) sizeHeaderToFit {
//call in viewLayoutSubView
UIView *myHeaderView = self.tableView.tableHeaderView;
[myHeaderView setNeedsLayout];
[myHeaderView layoutIfNeeded];
CGFloat height = [myHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
myHeaderView.frame = ({
CGRect headerFrame = myHeaderView.frame;
headerFrame.size.height = height;
headerFrame;
});
self.tableView.tableHeaderView = myHeaderView;
}
call it at viewDidLayoutSubView. Hope it helps bạn :))

Cannot change the Y cordinate of the UILabel programmatically

hi Im programmatically creating an UILabel like this
`
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[[UILabel alloc] init] initWithFrame:CGRectMake(0.0, _photoView.frame.size.height, _photoView.frame.size.width, 100.0)];
// _titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
_titleLabel.backgroundColor =[UIColor clearColor];
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:14];
_titleLabel.textAlignment = NSTextAlignmentRight;
[self addSubview:_titleLabel];
}
return _titleLabel;
}`
this _photoView is an UIImageView I have created already. I want to change the UILabel View Y value. But the problem is when I change this second parameter label y position is not changing. Any one can tell e the reason for this.
And this is how I created the ImageView
`
- (UIImageView *)photoView {
if (!_photoView) {
_photoView = [[UIImageView alloc] init];
_photoView.contentMode = UIViewContentModeScaleAspectFill;
_photoView.clipsToBounds = YES;
_photoView.layer.cornerRadius = 5;
_photoView.clipsToBounds = YES;
[self addSubview:_photoView];
}
return _photoView;
}`
Thanks
In this line , you have used two types init
[[[UILabel alloc] init] initWithFrame:CGRectMake(0.0, _photoView.frame.size.height, _photoView.frame.size.width, 100.0)]
change this line to
[[UILabel alloc] initWithFrame:CGRectMake(0.0, _photoView.frame.size.height, _photoView.frame.size.width, 100.0)]

text format trouble objective-c

need to make effect, that text is interrupted by another text/uiimageview, but cannot understand how does it works. For example i need to make interface similar to ios7 status bar where operator name such a "Oper ..." + icon + time. So i cannot do this right way
operatorName = [self getOperatorName];
UILabel *operatorLabel = [[UILabel alloc] init];
operatorLabel.backgroundColor = [UIColor clearColor];
operatorLabel.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:kStatusBarFontOperatorSize];
operatorLabel.textColor = kStatusBarTextColor;
operatorLabel.shadowOffset = CGSizeMake(0.f, -0.6);
operatorLabel.shadowColor = kStatusBarTextShadow;
operatorLabel.adjustsFontSizeToFitWidth = YES;
operatorLabel.text = operatorName;
operatorLabel.frame = CGRectMake(0.0, 0.0, operatorStrSize.width, operatorStrSize.height);
[operatorLabel sizeToFit];
/* connection type */
UIImageView *conImgView = [[UIImageView alloc] initWithImage:conImg];
/* time in status bar */
time = [self getStatusBarTime];
UILabel *statusBarLabel = [[UILabel alloc] init];
statusBarLabel.font = [UIFont fontWithName:#"HelveticaNeue-Medium" size:kStatusBarFontSize];
statusBarLabel.textColor = kStatusBarTextColor;
statusBarLabel.adjustsFontSizeToFitWidth = YES;
statusBarLabel.text = time;
int maxDistance = imgView.frame.size.width/2 - timeStrSize.width/2;
int connectionPower = 44;
double delimiter = 0;
NSString *cName = [self returnChoosenConnectionName];
if ([cName isEqualToString:#"Wi-Fi"]) {
delimiter = 6.5;
} else {
delimiter = 9.5;
}
int fullLine = connectionPower + operatorLabel.frame.size.width + delimiter + conImgView.frame.size.width;
if (fullLine > maxDistance) {
// need to interrupt text in operator name, but how ?
} else {
// all good placed
x = 44.0;
operatorLabel.frame = CGRectMake(x, 3.0, operatorStrSize.width , operatorStrSize.height);
[operatorLabel sizeToFit];
NSString *cName = [self returnChoosenConnectionName];
if ([cName isEqualToString:#"Wi-Fi"]) {
x += operatorLabel.frame.size.width + 6.5;
} else {
x += operatorLabel.frame.size.width + 9.5;
}
conImgView.frame = CGRectMake(x, 0.0, conImgView.frame.size.width, conImgView.frame.size.height);
[imgView addSubview:operatorLabel];
[imgView addSubview:conImgView];
}
statusBarLabel.frame = CGRectMake(imgView.frame.size.width/2 - timeStrSize.width/2, 2.5, timeStrSize.width , timeStrSize.height);
[imgView addSubview:statusBarLabel];
What i need:
what i have:
I would suggest to use autolayout rather than trying to calculate everything yourself. You may use XIB and set constraints in there or you may do everything programmatically. Here is a sample code that will get you started. It creates controls and sets constraints programatically; it doesn't use XIB.
- (void)viewDidLoad
{
[super viewDidLoad];
/*
Uncomment this if you would like to translate your subviews vertically.
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, 50)];
[self.view addSubview:view];
UIView *superview = view;
*/
UIView *superview = self.view;
UILabel *label1 = [[UILabel alloc] init];
label1.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:14.0];
label1.text = #"MTS";
[label1 sizeToFit];
[label1 setTranslatesAutoresizingMaskIntoConstraints:NO];
UILabel *label2 = [[UILabel alloc] init];
label2.font = [UIFont fontWithName:#"HelveticaNeue-Medium" size:14.0];
label2.text = #"1:22 PM";
[label2 sizeToFit];
[label2 setTranslatesAutoresizingMaskIntoConstraints:NO];
UIImageView *image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"strength.png"]];
UIImageView *image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"carrier.png"]];
[image1 setTranslatesAutoresizingMaskIntoConstraints:NO];
[image2 setTranslatesAutoresizingMaskIntoConstraints:NO];
[image1 sizeToFit];
[image2 sizeToFit];
[superview addSubview:image1];
[superview addSubview:label1];
[superview addSubview:image2];
[superview addSubview:label2];
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(image1, image2, label1, label2);
NSString *format = [NSString stringWithFormat:#"|-[image1(<=%f)]-[label1]-[image2(<=%f)]-[label2(>=20)]-|",
image1.frame.size.width, image2.frame.size.width];
NSArray *constraints;
constraints = [NSLayoutConstraint constraintsWithVisualFormat:format
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
}
When adding views to a layout in code iOS will attempt to convert the autosizing mask for that view to auto layout constraints. Those auto-generated constraints will conflict with any constraints added within the application code. It is essential to turn the translation off:
setTranslatesAutoresizingMaskIntoConstraints:NO
The result of the code is:

Can not adjust UIPopupController to display images

In my application (code listed below), I use a popover to display a series of colors that the user can choose. These colors are used for the color of the drawing they are completing above. I am trying to modify the popover to work the same way, except for this time I would want to display images (the images are saved in the application's documents folder as png files) instead of blocks of color. Listed below is the working code for the color selector popover. ColorGrid is a UIview which contains an NSArray Colors, as well as two NSUIntegers columnCount and rowCount. I have tried to replace the items in the colors array with UIImages of the png files, as well as UIImageViews but I have not been able to get a successful result (or a compilable one). Listed below is the working code. Could anyone show me how I can change the UIColor items to the images to show them in the grid?
- (IBAction)popoverStrokeColor:(id)sender {
StrokeColorController *scc = [[[StrokeColorController alloc] initWithNibName:#"SelectColorController" bundle:nil] autorelease];
scc.selectedColor = self.strokeColor;
[self doPopoverSelectColorController:scc sender:sender];
}
- (void)doPopoverSelectColorController:(SelectColorController*)scc sender:(id)sender {
[self setupNewPopoverControllerForViewController:scc];
scc.container = self.currentPopover;
self.currentPopover.popoverContentSize = scc.view.frame.size;
scc.colorGrid.columnCount = 2;
scc.colorGrid.rowCount = 3;
scc.colorGrid.colors = [NSArray arrayWithObjects:
//put the following below back in after testing
[UIColor blackColor],
[UIColor blueColor],
[UIColor redColor],
[UIColor greenColor],
[UIColor yellowColor],
[UIColor orangeColor],
//[UIColor purpleColor],
// [UIColor brownColor],
// [UIColor whiteColor],
// [UIColor lightGrayColor],
//[UIColor cyanColor],
//[UIColor magentaColor],
nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(colorSelectionDone:) name:ColorSelectionDone object:scc];
[self.currentPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //displays the popover and anchors it to the button
}
Thanks for your help. I am new to objective-c.
edit - heres the function with my attempt to insert the images instead of the colors
- (void)doPopoverSelectColorController:(SelectColorController*)scc sender:(id)sender {
[self setupNewPopoverControllerForViewController:scc];
scc.container = self.currentPopover;
self.currentPopover.popoverContentSize = scc.view.frame.size;
// these have to be set after the view is already loaded (which happened
// a couple of lines ago, thanks to scc.view...
scc.colorGrid.columnCount = 2;
scc.colorGrid.rowCount = 3;
//here we need to get the UIImage items to try to put in the array.
NSArray *pathforsave = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [pathforsave objectAtIndex:0];
//here we need to add the file extension onto the file name before we add the name to the path
//[fileName appendString:#".hmat"];
NSString *strFile = [documentDirectory stringByAppendingPathComponent:#"test.png"];
NSString *strFile1 = [documentDirectory stringByAppendingPathComponent:#"test1.png"];
NSString *strFile2 = [documentDirectory stringByAppendingPathComponent:#"test2.png"];
NSString *strFile3 = [documentDirectory stringByAppendingPathComponent:#"test3.png"];
NSString *strFile4 = [documentDirectory stringByAppendingPathComponent:#"test4.png"];
NSString *strFile5 = [documentDirectory stringByAppendingPathComponent:#"test5.png"];
//now for the Images
UIImage *image = [ UIImage imageWithContentsOfFile: strFile];
UIImage *image1 = [ UIImage imageWithContentsOfFile: strFile1];
UIImage *image2 = [ UIImage imageWithContentsOfFile: strFile2];
UIImage *image3 = [ UIImage imageWithContentsOfFile: strFile3];
UIImage *image4 = [ UIImage imageWithContentsOfFile: strFile4];
UIImage *image5 = [ UIImage imageWithContentsOfFile: strFile5];
UIImageView *imageview = [[[UIImageView alloc] initWithImage:image] autorelease];
[self.view addSubview:imageview];
UIImageView *imageview1 = [[[UIImageView alloc] initWithImage:image1] autorelease];
[self.view addSubview:imageview1];
UIImageView *imageview2 = [[[UIImageView alloc] initWithImage:image2] autorelease];
[self.view addSubview:imageview2];
UIImageView *imageview3 = [[[UIImageView alloc] initWithImage:image3] autorelease];
[self.view addSubview:imageview3];
UIImageView *imageview4 = [[[UIImageView alloc] initWithImage:image4] autorelease];
[self.view addSubview:imageview4];
UIImageView *imageview5 = [[[UIImageView alloc] initWithImage:image5] autorelease];
[self.view addSubview:imageview5];
imageview.image = image;
imageview1.image = image1;
imageview2.image = image2;
imageview3.image = image3;
imageview4.image = image4;
imageview5.image = image5;
scc.colorGrid.colors = [NSArray arrayWithObjects:
// When attempting to add the images like this - get the error identified expected
// after the e in image, at the end bracket. Putting a * does nothing to change the error
[image],
// When adding one of the Imageviews, i get the same error as above
//below is how I attempted to add it
[imageView],
//
nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(colorSelectionDone:) name:ColorSelectionDone object:scc];
[self.currentPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //displays the popover and anchors it to the button
}
Remove your square brackets around image and/or imageView :
scc.colorGrid.colors = [NSArray arrayWithObjects:
// Not : [image] but
image,
// or
imageView,
// Not : [imageView],
nil];