I have implemented UISegmentedControl with Direction theme using BASequenceControl from cocoacontrols.com.
I have added BASequenceControl.h and BASequenceControl.m classes and required images from GitHub
Great. Its working fine for me..However I have a concern with the last segment section tip.
Its displaying the junk space of last segment section.
Original Screen Shot
I need like this
The code I have Implemented
#import "BASequenceControl.h"
BASequenceControl *bASequenceControl = [[BASequenceControl alloc] init];
bASequenceControl.frame = CGRectMake(10, 10, 200, 44);
[bASequenceControl addSegmentWithTitle:#"First" animated:NO];
[bASequenceControl addSegmentWithTitle:#"Second" animated:NO];
bASequenceControl.leftMargin = -22;
bASequenceControl.rightMargin = 0;
bASequenceControl.overlapWidth = 22;
[self.view addSubview:bASequenceControl];
Any help on this is appreciated.
Thanks.
This is a pretty simple fix. You will have to edit the BASequenceControl.m file or you can duplicate the class and rename it.
The line that is causing the problem is in drawRect: it basically draws the grey arrow across the entire background of the control. Creating that nice gradient in the empty space.
[passiveSegmentImage drawInRect:CGRectMake(-passiveSegmentImage.size.width, 0,
w + 2 * passiveSegmentImage.size.width, h)];
You can change it to:
[passiveSegmentImage drawInRect:CGRectMake(0, 0,
w, h)];
Now you have to tell the control that it should not be opaque. Update the initializers like this.
- (void)awakeFromNib {
_selectedSegmentIndex = -1;
[self setOpaque:NO];
[super awakeFromNib];
}
- (id)init {
if ((self = [super init])) {
[self setOpaque:NO];
_selectedSegmentIndex = -1;
}
return self;
}
This is pretty quick and dirty, you could potentially make this settable with a property. Then submit a pull request to BaseAppKit, but I'll leave that to you. Here is a gist that you can copy and paste directly in BASequenceControl.m to fix the overhang.
https://gist.github.com/4632686
Edit: Make sure that you are using init as the initializer and then setFrame: (I'm not really sure why initWithFrame: wasn't overridden in the class.)
BASequenceControl *control = [[BASequenceControl alloc] init];
[control setFrame:CGRectMake(0, 0, 300, 40)];
Green background for dramatic effect
How about to use a mask like this :
to mask your SegmentedControl
Related
I am looking to create a representation of the sidebar shown in Keynote for iPad. How can I do this for iOS? I would imagine that a UITableView is needed, but not quite sure on the saving of the current screen?
Already seen one example project , but wasn't too much help
use this link I think this will helpful for you.first try with this code.
You will try this code add one scrollview on nib and set its contentsize on viewdidload
CGFloat x = 20;
for (int i = 0;i<[playerScores count];i++) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, 10, 60, 60)];
view.backgroundColor=[UIColor blueColor];
NSString *text = [NSString stringWithFormat:[playerScores objectAtIndex:i]];
[view setText:text];
[yardsScrollView addSubview:view];
[myLabel release];
x = x+125;
}
PlayersScore is a NSMutable array which have many text like how much view You want.
then also check this.
https://github.com/bjhomer/HSImageSidebarView
At first I want to say that i am new in iPhone application development.I want to make a tabbaritem when i will select a item of the tabbar then it should be look like that
Many Thanks In Advance.
Know it's already been answered, but wanted to offer an alternative approach.
Subclassing UITabBarController is a bad idea, according to the docs. I also had no end of trouble when I actually tried to use a UIImagePickerController as one of the view controllers behind the subclassed tabbar.
I took a much simpler approach just overlaying a uibutton over the tabbar item. Example project can be found here:
https://github.com/group6/RaisedCenterButton
It's just an example though. You're still going to need to do the work to incorporate it into an app.
Use the info in this Article
This has been covered in quite a few tutorials. How most of these apps achieve the effect is they put a custom UIButton which follows similar styling to the Tab Bar on top of the tab bar in the center.
iDev Recipes has an excellent tutorial with the code example
For this you need to create custom tab bar by Sub classing UITabBarController.
TabBarController.h file :
#interface TabBarController : UITabBarController<UITabBarControllerDelegate>
{
UITabBarController *tabController;
UIImageView *img1;
UIImageView *img2;
UIImageView *img3;
UIImageView *img4;
}
.m file
- (void)viewDidLoad
{
[self loadTabView];
//[self viewWillAppear:YES];
[super viewDidLoad];
}
- (void) loadTabView
{
tabController = [[UITabBarController alloc] init];
tabController.delegate = self;
tabController.tabBar.backgroundColor = [UIColor clearColor];
//set offset for tabbar items images.
int topOffset = 6;
int bottomOffset = 6;
UIEdgeInsets imageInset = UIEdgeInsetsMake(topOffset, 0, -bottomOffset, 0);
[self.view addSubview:tabController.view];
}
// reset the background image in custom tabbar.
- (void) setTabBarBackground {
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"btnbg.png"]];
img.frame = CGRectOffset(img.frame, 0, 1);
img.frame = CGRectMake(img.frame.origin.x, img.frame.origin.y-1, img.frame.size.width, img.frame.size.height);
[tabController.tabBar insertSubview:img atIndex:0];
[img release];
}
// reset the background image in custom tabbar.
- (void) resetTabBar : (NSString *) tabid
{
[img1 removeFromSuperview];
NSLog(#"tab id - %#",tabid);
switch ([tabid intValue]) {
case 0:
img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab-1.jpg"]];
break;
case 1:
img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab-2.jpg"]];
break;
case 2:
img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab-3.jpg"]];
break;
case 3:
img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab-4.jpg"]];
break;
case 4:
img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab-5.jpg"]];
break;
default:
break;
}
img1.frame = CGRectOffset(img1.frame, 0, 1);
[tabController.tabBar insertSubview:img1 atIndex:0];
[tabController.tabBar bringSubviewToFront:img1];
[img1 release];
}
// here push View controllers
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}
Hope it gives you idea..
I would advise not to do this. iOS users are used to the familiar tab bar functionality. The highlight is sufficient to let them know on which tab they are.
Your design idea is very attractive, but it comes at a cost. The area above the bar beside the rased bar item is wasted, or the size of other icons have to be reduced. This will make it more difficult to use, not easier.
Here is a good tip: take 2 hours out of your busy life and read the Apple Human Interface Guidelines for iOS from cover to cover. Its fascinating reading and will give you good guidance for design questions like this.
I have an UIView (320*300 the view of an UIViewController), I hope to display UINaviationCotroller and control the navigation within this view size.
Is it possible?
Thanks
interdev
Below you'll find out a snippet of code that does it. But let me give you a word of wisdom. Don't do it. Avoid at all costs. Apple doesn't recommend doing that. You will have nightmares and will be busy patching edge cases. It worked well in 3.x, with iOS 4 you'll have to work around a lot of special cases.
- (void) _adjustViewControllerforTicker {
TickerView* vv = [ApplicationContext getTickerView];
if ([PreferenceDataModel isTickerOn]&& self.navigationController.view.frame.origin.y==0) {
CGRect tableRect = self.tableView.frame;
self.tableView.frame = CGRectMake(tableRect.origin.x,tableRect.origin.y, tableRect.size.width, tableRect.size.height -20);
UINavigationController *nav = self.navigationController;
CGRect gframe = CGRectOffset(self.navigationController.view.frame, 0, 20);
self.navigationController.view.frame = gframe;
if (!vv) {
vv = [[TickerView alloc] initWithFrame:CGRectMake(0, 0, 480, 20)];
[nav.view addSubview:vv];
[vv release];
self.tableView.contentInset=UIEdgeInsetsMake(0,0,20.0,0.0);
}
}
if (![PreferenceDataModel isTickerOn]) {
self.tableView.contentInset= UIEdgeInsetsZero;
if (vv){
[vv removeFromSuperview];
vv=nil;
}
}
}
yes.. why do you think it wouldn't be? It is probably non-standard but technically it can be done
Okay so i have a very basic app with a view in it with one button. i have the controller set to only allow landscape. My problem is that after it is initialized, and then i click my button (which only has a log statement) , is different than the log statements i have at the end of my init.
I start the app in landscape mode on my simulator (same results on device though). Its like once i assign it , it just switches back. I tried this statement self.frame = CGRectMake(0, 0, 1024, 768);in my buttonClicked method, but that just distorted and shifted it.
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
//BUTTONS
attributesButton = [UIButton buttonWithType:UIButtonTypeCustom];
attributesButton.frame = CGRectMake(self.frame.size.width - buttonPadding - 35, self.frame.size.height/2 -22 -150, 35, 35);
[attributesButton setBackgroundImage:[UIImage imageNamed:#"loadIcon.png"] forState:UIControlStateNormal];
[attributesButton addTarget:self action:#selector(attributesButtonClicked)
forControlEvents:UIControlEventTouchUpInside];
[attributesButton setTitle:#"Attr" forState:UIControlStateNormal];
[self addSubview:attributesButton];
NSLog(#"Width: %f",self.frame.size.width);
NSLog(#"Height: %f",self.frame.size.height);
}
return self;
}
-(void)attributesButtonClicked
{
NSLog(#"Width: %f",self.frame.size.width);
NSLog(#"Height: %f",self.frame.size.height);
}
So that is my init. Sorry it looks so terrible im not sure why. My view controller:
- (void)loadView
{
NSLog(#"myViewController: loadView");
myView = [[myView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
self.view = myView;
}
Now this is the part that gets me, the log statements.
2010-08-27 15:16:55.242 tester[8703:40b] myViewController: loadView
2010-08-27 15:16:55.262 tester[8703:40b] Width: 1024.000000
2010-08-27 15:16:55.262 tester[8703:40b] Height: 768.000000
CLICK MY BUTTON HERE
2010-08-27 15:17:05.689 tester[8703:40b] Width: 748.000000
2010-08-27 15:17:05.689 tester[8703:40b] Height: 1024.000000
From what I've experienced, it seems like even though you are in landscape mode, if you're using autoresizing masks, you need to use a "portrait" frame when initializing your view using initWithFrame:
Try:
myView = [[myView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
If your view is tied to one of the standard view controllers (UINavigationController, UITabBarController, ...), the controller will update the frame size at runtime, no matter what you specify in initWithFrame.
That's actually a good thing, because you don't have to worry about orientation, toolbars taking up space, etc.
that's probably because the view is being autoresized by the parent view when you add it as a subview.
If you don't want that to happen (though you'd usually do for a fullscreen view) you can set the autoresizingMask to UIViewAutoresizingNone:
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
...
self.autoresizingMask = UIViewAutoresizingNone;
}
return self;
}
EDIT: ok, sorry, I just remembered that UIViewAutoresizingNone is actually the default value for autoresizingMask, so setting it to that value during initialization won't actually change anything. But the point is that the frame is changed by the superview when you add your view as a subview.
I have an NSMutableArray of custom views (that are pretty much 1 UITextView and 1 UILabel with a custom back ground image), these are created as they are need (I start with 2 (though the first one is only 2 UITextFields and the other is normal) of these). Now my issue here seems to be this: as soon as I try to edit any UITextView past the one in the 2nd view, it starts to run incredibly slow, not the app, just the textview. For example, as I type, the little blinky guy lags behind the text and when I click to copy/paste/cut/etc you can see the little balloon fly in from the upper left corner every time. I have run the static analyzer for leaks and come up with nothing and run it alongside some other the testing software in XCode and it does not appear to have any reason for this.
Any help would be greatly appreciated.
EDIT Adding code
Custom UIView, all that's really called on each
-(id)initWithFrame:(CGRect)frame andIdentifier:(NSInteger)_t {
if ((self = [super initWithFrame:frame])) {
// Initialization code
self.image = [UIImage imageNamed:#"page.png"];
self.tag = _t;
self.userInteractionEnabled = YES;
self.clipsToBounds = YES;
drawImage = self.image;
text = [[UITextView alloc] initWithFrame:CGRectMake(40.0, 40.0, self.frame.size.width - 80.0, self.frame.size.height - 80.0)];
text.delegate = self;
Lbl = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width - 30, self.frame.size.height - 30, 20, 20)];
Lbl.text = [NSString stringWithFormat:#"%d",self.tag];
[self addSubview:text];
[self addSubview:Lbl];
[Lbl release];
}
return self;
After that, I store the view in an array in the view controller and then stack 2 (used to be 3) at a time with one front and foremost and one below it. These get shuffled a bit but thats about it. I do not think it is a device issue, just a weird error that I cannot seem to catch.
found my problem, apparently some obscure animation block got left opened, which apparently animated everything else that was going on on the UIKit side. odd but makes sense