spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Variable width selection buttons on iOS


Your doubt is not entirely clear. If you are asking how to create buttons of variable width according to their text content, you can try the following :

- (UIButton *)setupVariableWidthButton{
    UIButton *button = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
    button.layer.cornerRadius = 5.0f;
    button.layer.masksToBounds = YES;
    [button setBackgroundColor:[UIColor
blueColor]];

    CGSize contstrainedSize = CGSizeMake(200,
40);//The maximum width and height 

    NSDictionary *attributesDictionary =
[NSDictionary dictionaryWithObjectsAndKeys:
                                          [UIFont
systemFontOfSize:15.0], NSFontAttributeName,
                                          nil];
    NSString *labelText = @"Long text";

//Calculate the required width and height just
enough to show the text
    CGRect frame = [labelText
boundingRectWithSize:contstrainedSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributesDictionary context:nil];

//Set the frame of the button using the calculated
required size
    button.frame = CGRectMake(5, 40,
CGRectGetWidth(frame)+5, CGRectGetHeight(frame));
    [button setTitle:labelText
forState:UIControlStateNormal];
    return button;
}

Categories : IOS

Related to : Variable width selection buttons on iOS
Android Buttons not streching to width of the screen
You need to use width as 0dip instead of wrap_content if you use weight property. <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="horizontal" android:paddingBottom="15sp" android:weightSum="2"> <com.beardedhen.androidbootstrap.BootstrapButton android:id="@+

Categories : Android
animate function: change div width by using radio buttons
You need it to remember what the original width was. Maybe, before you animate, check if a .data('originalWidth') has been set. If it has not, set it to what the width is. Then, on each later animate, base it off of that. Something like... function animateDiv(val) { var div = $('#cont'); if(div.data('originalWidth') == undefined) div.data('originalWidth', div.width()); var wi

Categories : Javascript
jquery variable: selection order doesn't update
Unfortunately there isn't any way. I previously asked about this on jQuery's forum, and was told 'no'. jakecigar there left a semi-solution, but it just abstracts away the calling: $.liveList = function(selector) { return function(){ return $(selector) } } var TRs =$.liveList('tr'); TRs().css('color','green') If you're not married to jQuery, you might also want to look at using plain DO

Categories : Jquery
c# wpf button with variable as name? same colours in all buttons
I'm assuming myColor is some class level SolidColorBrush since it isn't declared in the function. Given that, the following code simply changes the color of that brush, then assigns the brush to the new button instance: myColor.Color = Color.FromArgb(kolLos(), kolLos(), kolLos(), kolLos()); blueRectangle.Background = myColor; However, every button has the same brush instance, so when you

Categories : C#
Show a Selection When a Selection Option is Picked
You forgot to bind the event to the continent select. document.getElementById("continent").addEventListener("change", showhide); function showhide() { var sel = document.getElementById("continent").value; if (sel == 'Africa') { document.getElementById('africa').style.display = 'inline-block'; document.getElementById('america').style.display = 'none'; } else { document.getElem

Categories : Javascript
Recently Add
keychain iOS touchId prompted twice
-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fc748e37ea0'
Search Results Visibly Scrolling Underneath the Status Bar
How do I exclude an IOS 8 app extension from a build?
EXC_BAD_ACCESS when capturing a GPU frame
iOS 8 - Map keeps reanimating back to user location
Constantly refreshing background image of UIImageView IOS
UINavigationController keeps displaying popped view
Swift closure syntax using Shark Food Mute Switch?
MagicalRecord 3.0 not saving. No objects for the second build
iOS / Swift Can't add gesture to child class
iOS: Is there currently a way to prevent two view controllers being pushed or popped at the same time?
Checking if array contains two objects
How should turning of SCNLight affect background color?
Why don't my views show up in Storyboards and are greyed out in the left pane?
SWIFT convert NSTimeInteval to NSDate
BLE scanning is stopped when go to background?
Drawing a Rect on UIView
HLS playback via local HTTP server on iOS
Re-Assigning SKScene delegate protocol
Network lost on screen lock unlock
Annoying Xcode Error "file not found" #import
CoreData not firing faults
iOS:How do you change a view size/origin from another view controller class?
Changing a frame in viewDidLayoutSubviews
Animate multiple shapes in UIView
Add NSIntegers ONLY when 2nd NSInteger Changes Value
Facebook SDK, fetching friends
How to get Storyboard to support dynamically sized cells in UICollectionView?
GCD / NSOperationQueue EXC_BAD_ACCESS
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.