Cómo aumentar la altura de UIProgressView


Estoy creando UIProgressView desde nib. Quiero aumentar su altura, pero se fija a 9. Para iPad Necesito aumentar su altura. Cómo se puede hacer?

Gracias de antemano.

Author: rgettman, 2010-08-09

19 answers

No se puede cambiar la altura de UIProgressView a través de nib. Si desea cambiar la altura, debe implementarla a través del método de dibujo personalizado.

 4
Author: raaz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-08-09 06:03:21

Use CGAffineTransform para cambiar las dimensiones:

CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 3.0f);  
progressView.transform = transform;
 164
Author: ashayk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-24 13:58:21

Usar restricciones de diseño funcionó para mí:

introduzca la descripción de la imagen aquí

 74
Author: Logan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-24 21:11:08

Coloque esta fuente

@implementation UIProgressView (customView)
- (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = CGSizeMake(self.frame.size.width, 9);
    return newSize;
}
@end
 25
Author: Shoaib,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-15 19:17:26

Simplemente establezca el marco de UIProgressView en código después de que se haya inicializado. Eg:

UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
// progressView's frame will be small/standard height

progressView.frame = CGRectMake(0, 0, 100, 20);
// Now the frame is set to my custom rect.

Esto está funcionando para mí en iOS 5. Estoy usando trackImage personalizado y progressImage sin embargo. Mi código se ve así. Tenga en cuenta que estoy agregando el progressView a otra vista y quiero que sea del mismo tamaño que la vista que contiene, por lo tanto, establecer el marco a sí mismo.obligado.

_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
_progressView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_progressView.trackImage = [[UIImage imageNamed:@"search-progress-track"] resizableImageWithCapInsets:UIEdgeInsetsMake(3.0f, 3.0f, 3.0f, 3.0f)];
_progressView.progressImage = [[UIImage imageNamed:@"search-progress"] resizableImageWithCapInsets:UIEdgeInsetsMake(3.0f, 3.0f, 3.0f, 3.0f)];
_progressView.frame = self.bounds;
[_progressView setProgress:0.5];
 12
Author: orj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-01 07:15:19

Hay una forma sencilla de cambiar la altura dentro de Interface Builder. No se requiere código y su cambio se mostrará en IB.

Seleccione el objeto UIProgressView en su storyboard o xib, elija Editor > Pin > Altura. Esto creará una restricción de altura y le permitirá cambiar su valor en el Inspector de atributos en su panel más a la izquierda (Utiliza).

 11
Author: Matt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-06 22:05:26

El siguiente código funciona en el swift xCode más reciente:

var transform : CGAffineTransform = CGAffineTransformMakeScale(1.0, 6.0)
           progressView.transform = transform
 9
Author: user4935372,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-25 03:28:44

Swift 3:

progressView.transform = progressView.transform.scaledBy(x: 1, y: 9)
 8
Author: RaziPour1993,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-14 13:09:18

Aquí está la solución

Puede usar transform, pero surge el problema de que -> cuando cambia la orientación del dispositivo, UIProgressView height se convierte en original.

Así que la mejor manera de aumentar la altura de UIProgressView es

yourProgressView.progressImage=[UIImage imageNamed:@"image1.png"];
yourProgressView.trackImage = [UIImage imageNamed:@"image2.png"];
// IMPORTANT: image1/image2 height (in pixel) = height that you want for yourProgressView.
// no need to set other properties of yourProgressView.

Gracias

 6
Author: Mayur Kothawade,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-06 12:12:49

También puede usar el diseño automático para lograr el mismo aspecto y funciona en iOS 7.1. Simplemente agregue una restricción de altura igual a la altura que desea que tenga su barra de progreso. Echa un vistazo a esta respuesta en esta pregunta similar para más detalles.

Https://stackoverflow.com/a/19606981/142358

 6
Author: Steve Moser,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:26:07

Para iOS 7+, use Core Graphics y CATransform3DScale para escalar la capa en esa vista:

CATransform3D transform = CATransform3DScale(progressView.layer.transform, 1.0f, 3.0f, 1.0f);
progressView.layer.transform = transform;

Solo asegúrese de hacer esto después de establecer el marco de progressView, no antes.

 5
Author: Mike Onorato,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-13 08:45:40

Swift3

var transform : CGAffineTransform = CGAffineTransform(scaleX: 1.0, y: 6.0)
progressBar.transform = transform 

Adición

Si estás trabajando con una clase IBDesignable, puedes modificarla con esto desde tu storyboard:

@IBInspectable var progressBarHeight: CGFloat = 2.0 {
    didSet {
        let transform = CGAffineTransform(scaleX: 1.0, y: progressBarHeight)
        self.progressView.transform = transform
    }
}
 5
Author: Amit Jagesha シ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-29 14:56:14

Para iOS 7 y superiores, hice lo siguiente que (a) funciona y (b) no genera una advertencia:

Primero agregue UIProgressView a mi Controlador de vista en el guion gráfico. Luego agregue una restricción de altura a UIProgressView mediante CTRL+Arrastrando UIProgressView a sí mismo. La restricción se creará con un valor predeterminado de 2. Deja eso en paz.

Ahora para cambiar la altura agregue un IBOutlet a la subclase UIViewController en código como este:

@property (nonatomic, weak) IBOutlet NSLayoutConstraint *progressHeight;

Entonces en su código, probablemente - viewDidLoad, añadir:

self.progressHeight.constant = 9;

Esto debería funcionar muy bien para ti.

 4
Author: i_am_jorf,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-15 19:13:48

Aquí hay una barra de progreso de terceros que permite establecer la altura. https://github.com/yannickl/YLProgressBar

introduzca la descripción de la imagen aquí

Establecer marco a través de código o generador de interfaz. Sin embargo, es posible que desee desactivar la animación o las rayas.

Aquí está el código para una gruesa barra de progreso verde:

YLProgressBar *bar = [[YLProgressBar alloc] initWithFrame:CGRectMake(0, 100, 100, 50)];
bar.progress = 0.5;
bar.type = YLProgressBarTypeFlat;
bar.hideStripes = YES;
bar.behavior = YLProgressBarBehaviorDefault;
bar.progressTintColors = @[[UIColor greenColor], [UIColor greenColor]];

introduzca la descripción de la imagen aquí

 2
Author: ftvs,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-01 05:28:26

Puede implementar una categoría (nuevo archivo-categoría) y simplemente agrega la categoría al comienzo de tu clase. Funciona bien también con iboutlet (plumín/guion gráfico).

El código es solo

@interface UIProgressView (heavyView)
@end

@implementation UIProgressView (heavyView)
- (CGSize)sizeThatFits:(CGSize)size
{
    CGSize newSize = CGSizeMake(size.width, 9);
    return newSize;
}
@end

Si desea aplicar el cambio para una sola progressView y tiene más de una progressView en su clase, puede usar una subclase en su lugar.

 2
Author: Daniel C.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-31 15:48:22

El método de Mayur funcionó bien para mí en iOS 7, aquí está mi código (usa UIImage+BBlock)

    CGFloat progressViewHeight = 5;
    [[UIProgressView appearance] setProgressImage:[UIImage imageForSize:CGSizeMake(1, progressViewHeight) withDrawingBlock:^{
        CGContextRef context = UIGraphicsGetCurrentContext();
        UIColor * colortoUse = [UIColor blueColor];
        CGContextSetFillColorWithColor(context, [colortoUse CGColor]);
        CGContextFillRect(context, CGRectMake(0, 0, 1, progressViewHeight));
    }]];

    [[UIProgressView appearance] setTrackImage:[UIImage imageForSize:CGSizeMake(1, progressViewHeight) withDrawingBlock:^{
        CGContextRef context = UIGraphicsGetCurrentContext();
        UIColor * colortoUse = [UIColor progressViewBackgroundColor];
        CGContextSetFillColorWithColor(context, [colortoUse CGColor]);
        CGContextFillRect(context, CGRectMake(0, 0, 1, progressViewHeight));
    }]];
 0
Author: Jason,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-22 13:59:30

En lugar de usar interface builder, la altura de UIProgressView se puede cambiar agregándole restricciones mediante programación.

UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.translatesAutoresizingMaskIntoConstraints = NO;
CGRect frame = CGRectMake(100, 200, 200, 50);
[self.view addSubview:progressView];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-y-[progressView(height)]" options:0
                                                                  metrics:@{@"y": @(CGRectGetWidth(frame)),
                                                                            @"height": @(CGRectGetHeight(frame))}
                                                                    views:NSDictionaryOfVariableBindings(progressView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-x-[progressView(width)]" options:0
                                                                  metrics:@{@"x": @(CGRectGetMinX(frame)),
                                                                            @"width": @(CGRectGetWidth(frame))}
                                                                    views:NSDictionaryOfVariableBindings(progressView)]];
 0
Author: user3480295,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-03 15:39:16

Mi sugerencia sería colocar una vista de contenedor en la vista de su controlador de vista en Diseño automático. Asegúrese de que es el tamaño que desea para su barra de progreso. Ahora arrastre una vista de progreso dentro del contenedor y fije todos los lados a los límites del contenedor. Debería ver inmediatamente el cambio de tamaño de la vista de progreso para ajustarse a los límites de su contenedor.

Cambio de tamaño de UIProgressView

 0
Author: Stephen Paul,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-16 04:17:06

Simple. Swift 4.

Barra de progreso.transform = CGAffineTransform (scaleX: self.vista.marco.width / ProgressBar.marco.ancho, y: auto.vista.marco.altura / progressBar.marco.altura)

 -1
Author: Timmy Sorensen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-24 21:56:10